10.27 simulated match
阿新 • • 發佈:2017-10-27
分享 match scan name i++ tor type tdi sca
#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++) 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,L[MN+5],a[MN+5],A[MN+5];ll sum[MN+5]; int main(){O("implement");n=read(); f(n)if(read()==1){int x=read();sum[i]=sum[i-1]+1;L[i]=-1;A[i]=x;if(m<MN)a[++m]=x;}else{int l=read(),c=read();sum[i]=sum[i-1]+1LL*l*c;L[i]=l; for(int i=1;m<MN&&i<=c;++i) for(int j=1;j<=l&&m<MN;++j)a[++m]=a[j];} for(int Q=read();Q;--Q){ll x;x=read(); int pos=lower_bound(sum+1,sum+n+1,x)-sum; L[pos]==-1?printf("%d\n",A[pos]):printf("%d\n",a[(x-sum[pos-1]-1)%L[pos]+1]);}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\n",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\n",ans);f(ans)printf("%d %d %d\n",a[i],b[i],c[i]); return 0;}
10.27 simulated match