Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef struct arb {
  5. short sum;
  6. arb *left,*right;
  7. arb() { left=right=NULL; sum=0; }
  8. }*Arb;
  9.  
  10. int i,j,n,m,lung,k,a[1000005],x,y,N,pozx[1000005],pozy[1000005],rs;
  11. char c,semn;
  12. string s,ans;
  13. Arb root=new arb;
  14.  
  15. void update(int left,int right,Arb nod) {
  16. if(left==right) nod->sum+=y;
  17. else {
  18. if(!nod->left) nod->left=new arb;
  19. if(!nod->right) nod->right=new arb;
  20.  
  21. int pivot=(left+right)/2;
  22. if(x<=pivot) update(left,pivot,nod->left);
  23. else update(pivot+1,right,nod->right);
  24. nod->sum=nod->left->sum+nod->right->sum;
  25. }
  26. }
  27.  
  28. void query(int left,int right,Arb nod) {
  29. if(left>=x && right<=y) rs+=nod->sum;
  30. else {
  31. int pivot=(left+right)/2;
  32. if(x<=pivot && nod->left && nod->left->sum) query(left,pivot,nod->left);
  33. if(y>pivot && nod->right && nod->right->sum) query(pivot+1,right,nod->right);
  34. }
  35. }
  36.  
  37. int main()
  38. {
  39. ios_base::sync_with_stdio(0); cin.tie(0);
  40.  
  41. cin>>n>>m; getline(cin,s);
  42. getline(cin,s); lung=s.length();
  43.  
  44. for(i=0,k=1;i<lung;++i,N=max(N,a[k++]))
  45. while(s[i]>='0' && s[i]<='9' && i<lung) a[k]*=10,a[k]+=s[i]-'0',++i;
  46.  
  47. for(i=1;i<=n;++i,pozx[i-1]=j)
  48. for(j=i-1;j>0 && a[i]>=a[j];j=pozx[j]);
  49.  
  50. for(i=1;i<=n;++i) pozy[i]=n+1;
  51.  
  52. for(i=n;i;--i,pozy[i+1]=j)
  53. for(j=i+1;j<=n && a[i]>a[j];j=pozy[j]);
  54.  
  55. for(i=1;i<=n;++i)
  56. {
  57. --pozy[i]; ++pozx[i]; x=a[i];
  58. y=(1LL*(pozy[i]-i+1)*(i-pozx[i]+1))%2;
  59. if(y) update(1,N,root);
  60. }
  61.  
  62. while(m--)
  63. {
  64. getline(cin,s); k=rs=0; semn=s[0]; lung=s.length(); c=s[lung-1];
  65.  
  66. for(i=2;i<lung-2;++i) k*=10,k+=s[i]-'0';
  67.  
  68. if(semn=='=') x=y=k;
  69. if(semn=='<') x=1,y=k-1;
  70. if(semn=='>') x=k+1,y=N;
  71.  
  72. if(x<=y) query(1,N,root);
  73.  
  74. if(c=='C') ans+=(rs&1 ? 'C':'D');
  75. else ans+=(rs&1 ? 'D':'C');
  76. }
  77.  
  78. cout<<ans<<'\n';
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement