zoukankan      html  css  js  c++  java
  • 10.27 simulated match

    #include<iostream>
    #include<cstdio>
    #define MN 100000
    using namespace std;
    #define O(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
    #define ct   register int
    #define f(c)   for(ct i=1;i<=c;i++)
    #define ll  long long
    int read(){ct f=1,x=0;char c=getchar();
       for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
       for(;'0'<=c&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);return x*f;}
    int n,m,L[MN+5],a[MN+5],A[MN+5];ll sum[MN+5];
    int main(){O("implement");n=read();//read the total_num of the operations 
        f(n)if(read()==1){int x=read();//read the number
             sum[i]=sum[i-1]+1;//use sum to mark after each operation's total_num of numbers
             L[i]=-1;//L use to mark change_numbers' num,because here we didn't change the numbers before ,so we just set it to -1
             A[i]=x;//use A[i] to mark the new number
             if(m<MN)a[++m]=x;//if it is able to push it into the array just push it(resort the violence)
        }
        //operation 1:pish a number into the tail
            else{int l=read(),c=read();//read the change_numbers' num and push_times 
                sum[i]=sum[i-1]+1LL*l*c;//use sum to mark after each operation's total_num of numbers
                L[i]=l;//mark the change_numbers' num
                for(int i=1;m<MN&&i<=c;++i)
                //inside the section of 1 to MN,we can make operation in violence(just push them into the tail in violence)
                //this loop means push_times
                    for(int j=1;j<=l&&m<MN;++j)
                //inside the section of 1 to MN,we can make operation in violence(just push them into the tail in violence)
                //this loop means change_numbers
                    a[++m]=a[j];//push numbers into the tail
                }
        //operation 2:delete the first_several numbers and push them into the tail several times
        for(int Q=read();Q;--Q){//read the total_num of inquiries and make a loop in order to read each inquiry
            ll x;scanf("%lld",&x);//read each enquiry
            int pos=lower_bound(sum+1,sum+n+1,x)-sum;
            //use binary research to find x's location 
            L[pos]==-1?printf("%d
    ",A[pos]):printf("%d
    ",a[(x-sum[pos-1]-1)%L[pos]+1]);
            //if it's location has not changed,just out num of it's location.
            //or ,just out the changed location  
    }return 0;}

    #include<cstring>
    #include<cstdio>
    #define MN 1000000
    using namespace std;
    #define O(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
    #define ct   register int
    #define f(c)   for(ct i=1;i<=c;i++)
    int min(int a,int b){return a<b?a:b;}
    typedef  long long ll;
    int read(){ct f=1,x=0;char c=getchar();
       for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
       for(;'0'<=c&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);return x*f;}
    char st[MN+5];int n,m;
    struct data{int ans,l,r;
        friend data operator +(const data&a,const data&b){
            int mn=min(a.l,b.r);return (data){a.ans+b.ans+mn,a.l+b.l-mn,a.r+b.r-mn}; }  };
    struct Tree{int l,r;data x;}T[MN*4+5];
    void Build(int x,int l,int r){
        if((T[x].l=l)==(T[x].r=r)) {T[x].x=(data){0,st[l]=='(',st[l]==')'};return;}    
        int mid=l+r>>1;Build(x<<1,l,mid);Build(x<<1|1,mid+1,r);
        T[x].x=T[x<<1].x+T[x<<1|1].x; }
    data Query(int x,int l,int r){
        if(T[x].l==l&&T[x].r==r)return T[x].x;int mid=T[x].l+T[x].r>>1;
        if(r<=mid)return Query(x<<1,l,r);
        else if(l>mid)return Query(x<<1|1,l,r);
        else return Query(x<<1,l,mid)+Query(x<<1|1,mid+1,r);}
    int main(){O("data");n=read();m=read();
        scanf("%s",st+1);n=strlen(st+1);Build(1,1,n);
        f(m){int l=read(),r=read();printf("%d
    ",2*Query(1,l,r).ans);    }return 0;}

    #include<iostream>
    #include<cstdio>
    #define MN 200000
    using namespace std;
    #define O(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
    #define ct   register int
    #define f(c)   for(ct i=1;i<=c;i++)
    typedef  long long ll;
    int read(){ct f=1,x=0;char c=getchar();
       for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
       for(;'0'<=c&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);return x*f;}
    int n,m,head[MN+5],cnt=0,a[MN+5],b[MN+5],c[MN+5],ans=0,vis[MN+5],flag[MN+5];
    pair<int,int> q[MN+5];
    struct edge{int to,next,w;}e[MN*2+5];
    inline void ins(int f,int t,int w){e[++cnt]=(edge){t,head[f],w};head[f]=cnt;e[++cnt]=(edge){f,head[t],w};head[t]=cnt; }
    void dfs(int x,int fa,int fat){ vis[x]=1;int top=0;
        for(int i=head[x];i;i=e[i].next)
            if(!vis[e[i].to]) dfs(e[i].to,e[i].w,x);
        for(int i=head[x];i;i=e[i].next)
            if(e[i].to!=fat&&!flag[e[i].w])
                 q[++top]=make_pair(e[i].to,e[i].w);
        if(fa)q[++top]=make_pair(fat,fa);
        for(int i=2;i<=top;i+=2)a[++ans]=q[i].first,b[ans]=x,c[ans]=q[i-1].first,flag[q[i].second]=flag[q[i-1].second]=1;}
    int main(){O("graph");n=read();m=read();
        f(m)ins(read(),read(),i);f(n)if(!vis[i]) dfs(i,0,0);
        printf("%d
    ",ans);f(ans)printf("%d %d %d
    ",a[i],b[i],c[i]); return 0;}
  • 相关阅读:
    BZOJ.4842.[NEERC2016]Delight for a Cat(费用流)
    LOJ.6060.[2017山东一轮集训Day1/SDWC2018Day1]Set(线性基)
    BZOJ.5319.[JSOI2018]军训列队(主席树)
    BZOJ.4212.神牛的养成计划(Trie 可持久化Trie)
    HDU.5385.The path(构造)
    HDU.4903.The only survival(组合 计数)
    Codeforces.1043F.Make It One(DP 容斥)
    BZOJ.5110.[CodePlus2017]Yazid 的新生舞会(线段树/树状数组/分治)
    洛谷.3676.小清新数据结构题(树链剖分 树状数组)
    BZOJ.4598.[SDOI2016]模式字符串(点分治 Hash)
  • 原文地址:https://www.cnblogs.com/muzu/p/7742346.html
Copyright © 2011-2022 走看看