Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef struct arb {
- short sum;
- arb *left,*right;
- arb() { left=right=NULL; sum=0; }
- }*Arb;
- int i,j,n,m,lung,k,a[1000005],x,y,N,pozx[1000005],pozy[1000005],rs;
- char c,semn;
- string s,ans;
- Arb root=new arb;
- void update(int left,int right,Arb nod) {
- if(left==right) nod->sum+=y;
- else {
- if(!nod->left) nod->left=new arb;
- if(!nod->right) nod->right=new arb;
- int pivot=(left+right)/2;
- if(x<=pivot) update(left,pivot,nod->left);
- else update(pivot+1,right,nod->right);
- nod->sum=nod->left->sum+nod->right->sum;
- }
- }
- void query(int left,int right,Arb nod) {
- if(left>=x && right<=y) rs+=nod->sum;
- else {
- int pivot=(left+right)/2;
- if(x<=pivot && nod->left && nod->left->sum) query(left,pivot,nod->left);
- if(y>pivot && nod->right && nod->right->sum) query(pivot+1,right,nod->right);
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0);
- cin>>n>>m; getline(cin,s);
- getline(cin,s); lung=s.length();
- for(i=0,k=1;i<lung;++i,N=max(N,a[k++]))
- while(s[i]>='0' && s[i]<='9' && i<lung) a[k]*=10,a[k]+=s[i]-'0',++i;
- for(i=1;i<=n;++i,pozx[i-1]=j)
- for(j=i-1;j>0 && a[i]>=a[j];j=pozx[j]);
- for(i=1;i<=n;++i) pozy[i]=n+1;
- for(i=n;i;--i,pozy[i+1]=j)
- for(j=i+1;j<=n && a[i]>a[j];j=pozy[j]);
- for(i=1;i<=n;++i)
- {
- --pozy[i]; ++pozx[i]; x=a[i];
- y=(1LL*(pozy[i]-i+1)*(i-pozx[i]+1))%2;
- if(y) update(1,N,root);
- }
- while(m--)
- {
- getline(cin,s); k=rs=0; semn=s[0]; lung=s.length(); c=s[lung-1];
- for(i=2;i<lung-2;++i) k*=10,k+=s[i]-'0';
- if(semn=='=') x=y=k;
- if(semn=='<') x=1,y=k-1;
- if(semn=='>') x=k+1,y=N;
- if(x<=y) query(1,N,root);
- if(c=='C') ans+=(rs&1 ? 'C':'D');
- else ans+=(rs&1 ? 'D':'C');
- }
- cout<<ans<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement