fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int Nmax=30000+5;
  4. int n,q,a,b,c;
  5. int arr[Nmax];
  6.  
  7. vector<int>tree[5*Nmax];
  8.  
  9. void build(int node,int start,int end){
  10. if(start==end){
  11. tree[node].push_back(arr[start]);
  12. return;
  13. }
  14. int mid=start+(end-start)/2;
  15. build(node*2+1,start,mid);
  16. build(node*2+2,mid+1,end);
  17. merge(tree[node*2+1].begin(),tree[node*2+1].end(),tree[node*2+2].begin(),tree[node*2+2].end(),back_inserter(tree[node]));
  18. }
  19.  
  20. int query(int node,int start,int end,int l,int r,int v){
  21. if(l>end||r<start)
  22. return 0;
  23. if(start>=l&&end<=r){
  24. int k=upper_bound(tree[node].begin(),tree[node].end(),v)-tree[node].begin();
  25. return (end-start+1)-k;
  26. }
  27. int mid=start+(end-start)/2;
  28. return query(node*2+1,start,mid,l,r,v)+query(node*2+2,mid+1,end,l,r,v);
  29. }
  30.  
  31. int main(){
  32. cin>>n;
  33. for(int i=0;i<n;i++)
  34. cin>>arr[i];
  35. build(0,0,n-1);
  36. cin>>q;
  37. int ans=0;
  38. while(q--){
  39. cin>>a>>b>>c;
  40. int i,j,k;
  41. i=ans^a;
  42. j=ans^b;
  43. k=ans^c;
  44. if(i<1)
  45. i=1;
  46. if(j>n)
  47. j=n;
  48. if(i>j){
  49. ans=0;
  50. cout<<ans<<endl;
  51. continue;
  52. }
  53. i--;
  54. j--;
  55. ans=query(0,0,n-1,i,j,k);
  56. cout<<ans<<endl;
  57. }
  58. return 0;
  59. }
Runtime error #stdin #stdout 0s 6496KB
stdin
Standard input is empty
stdout
Standard output is empty