2223: [Coci 2009]PATULJCI
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1270 Solved: 541
[Submit][Status][Discuss]
Description
Input
Output
10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10
Sample Input
no
yes 1
no
yes 1
no
yes 2
no
yes 3
yes 1
no
yes 1
no
yes 2
no
yes 3
Sample Output
HINT
Notice:输入第二个整数是序列中权值的范围Lim,即1<=ai(1<=i<=n)<=Lim。
1<=Lim<=10000
Source
当然是主席树辣
2439109 | zhangenming | 2223 | Accepted | 177076 kb | 960 ms | C++/Edit | 1741 B | 2017-12-04 19:29:22 |
2439086 | zhangenming | 2223 | Wrong_Answer | 177076 kb | 36 ms | C++/Edit | 1764 B | 2017-12-04 19:20:46 |
2439080 | zhangenming | 2223 | Wrong_Answer | 177076 kb | 32 ms | C++/Edit | 1764 B | 2017-12-04 19:18:20 |
2439079 | zhangenming | 2223 | Compile_Error | 0 kb | 0 ms | C++/Edit | 1765 B | 2017-12-04 19:17:53 |
我也是醉了,这么简单的题,先CE,再WA
原来是没有删调试代码
#include <bits/stdc++.h> #define ll long long using namespace std; inline int read(){ int x=0;int f=1;char ch=getchar(); while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();} while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} return x*f; } const int MAXN=1e6+10; struct node{ int son[2],sum; }T[MAXN*5]; int rsum,a[10000010],b[10000010],siz=0,root[10000010],n,m,lim; namespace zhangenming{ inline void insert(int l,int r,int x,int &y,int v){ y=++siz;T[y].sum=T[x].sum+1; if(l==r) return; T[y].son[0]=T[x].son[0];T[y].son[1]=T[x].son[1]; int mid=(l+r)>>1; if(v<=mid) insert(l,mid,T[x].son[0],T[y].son[0],v); else insert(mid+1,r,T[x].son[1],T[y].son[1],v); } inline int get(int L,int R){ int l=1;int r=lim; int x=root[L-1];int y=root[R];int tmp=(R-L+1)>>1; int mid; while(l!=r){ int mid=(l+r)>>1; if(T[y].sum-T[x].sum<=tmp) return 0; if(T[T[y].son[0]].sum-T[T[x].son[0]].sum>tmp){ y=T[y].son[0];x=T[x].son[0];r=mid; } else if(T[T[y].son[1]].sum-T[T[x].son[1]].sum>tmp){ y=T[y].son[1];x=T[x].son[1];l=mid+1; } else return 0; } return l; } void init(){ n=read();lim=read(); for(int i=1;i<=n;i++){ int xx=read(); insert(1,lim,root[i-1],root[i],xx); } } void solve(){ m=read(); for(int i=1;i<=m;i++){ int xx=read();int yy=read(); int k=get(xx,yy); if(!k) printf("no "); else printf("yes %d ",k); } } } int main(){ //freopen("All.in","r",stdin); //freopen("a.out","w",stdout); using namespace zhangenming; init(); solve(); return 0; }
对拍代码
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ freopen("All.in","w",stdout); srand(time(int(NULL))); int n=rand()%10007+1; int m=rand()%10007+1+n; cout<<n<<' '<<m<<endl; for(int i=1;i<=n;i++){ printf("%d ",rand()%m+1); } n=m; m=rand()%10007; cout<<m<<endl; for(int i=1;i<=m;i++){ int k=rand()%n+1;int t=rand()%n+1; if(k>t) swap(k,t); printf("%d %d ",k,t); } return 0; }