Sanath12345

Untitled

Apr 22nd, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. //Problem link :
  2. //done by sanath kumar
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long int
  6. #define ld long double
  7. #define mod 1000000007
  8. #define inf 1e9
  9. #define endl "\n"
  10. #define pb push_back
  11. #define vi vector<ll>
  12. #define vs vector<string>
  13. #define pii pair<ll,ll>
  14. #define ump unordered_map
  15. #define mp make_pair
  16. #define pq_max priority_queue<ll>
  17. #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
  18. #define all(v) v.begin(),v.end()
  19. #define ff first
  20. #define ss second
  21. #define mid(l,r) (l+(r-l))/2
  22. #define bitc(x) __builtin_popcount(x)
  23. #define loop(i,a,b) for(int i=(a);i<=(b);i++)
  24. #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
  25. #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
  26. #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
  27. #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  28. template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
  29. template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
  30.  
  31. void err(istream_iterator<string> it){}
  32. template<typename T,typename... Args>
  33. void err(istream_iterator<string> it,T a,Args... args){
  34. cout<<*it<<" = "<<a<<endl;
  35. err(++it,args...);
  36. }
  37.  
  38. void file_i_o(){
  39. ios_base::sync_with_stdio(false);
  40.  
  41. cin.tie(0);
  42. cout.tie(0);
  43. #ifndef ONLINE_JUDGE
  44. freopen("input.txt","r",stdin);
  45. freopen("output.txt","w",stdout);
  46. #endif
  47. }
  48. void update(int arr[],int sum[][11],int lazy[],int n,int b,int l,int r,int y,int x){
  49. int bnl=l/b,bnr=r/b;
  50. loop(i,0,10){
  51. sum[bnl][i]=0;
  52. sum[bnr][i]=0;
  53. }
  54. for(int i=l;i<=r and i<(bnl+1)*b;i++){
  55. arr[i]=(arr[i]+y)%x;
  56. }
  57. for(int i=bnl*b;i<n and i<(bnl+1)*b;i++) sum[bnl][arr[i]]++;
  58. if(bnl!=bnr){
  59. for(int i=bnr*b;i<=r;i++){
  60. arr[i]=(arr[i]+y)%x;
  61. }
  62. for(int i=bnr*b;i<n and i<(bnr+1)*b;i++) sum[bnr][arr[i]]++;
  63. for(int i=bnl+1;i<=bnr-1;i++){
  64. lazy[i]+=y;
  65. }
  66. }
  67. }
  68. int query(int arr[],int sum[][11],int lazy[],int n,int b,int l,int r,int x){
  69. int bnl=l/b,bnr=r/b,ans=0;
  70.  
  71. for(int i=l;i<=r and i<(bnl+1)*b;i++){
  72. if((arr[i]+lazy[bnl])%x==0){
  73. ans++;
  74. }
  75. }
  76. if(bnl!=bnr){
  77. for(int i=bnr*b;i<=r;i++){
  78. if((arr[i]+lazy[bnr])%x==0){
  79. ans++;
  80. }
  81. }
  82. for(int i=bnl+1;i<=bnr-1;i++){
  83. ans+=sum[i][(x-lazy[i])%x];
  84. }
  85. }
  86. return ans;
  87. }
  88. int main(){
  89. file_i_o();
  90. clock_t begin=clock();
  91. int n,q,x;
  92. cin>>n>>q>>x;
  93. int B[n];
  94. int arr[n];
  95. loop(i,0,n-1) cin>>B[i];
  96. loop(i,0,n-1){
  97. arr[i]=B[i]%x;
  98. }
  99. int b=sqrt(n);
  100. int sum[(n/b)+1][11],lazy[(n/b)+1];
  101. loop(i,0,(n/b)){
  102. lazy[i]=0;
  103. loop(j,0,x-1){
  104. sum[i][j]=0;
  105. }
  106. }
  107. for(int i=0;i<=(n/b);i++){
  108. for(int j=i*b;j<(i+1)*b and j<n;j++){
  109. sum[i][arr[j]]++;
  110. }
  111. }
  112. while(q--){
  113. int type;
  114. cin>>type;
  115. if(type==1){
  116. int l,r,y;
  117. cin>>l>>r>>y;
  118. l--,r--;
  119. update(arr,sum,lazy,n,b,l,r,y%x,x);
  120. }
  121. else{
  122. int l,r;
  123. cin>>l>>r;
  124. l--;r--;
  125. cout<<query(arr,sum,lazy,n,b,l,r,x)<<endl;
  126. }
  127. }
  128. #ifndef ONLINE_JUDGE
  129. clock_t end=clock();
  130. cout<<"\n\n\nExecuted in :"<<double(end-begin)/CLOCKS_PER_SEC*1000<<" ms"<<endl;
  131. #endif
  132. }
Advertisement
Add Comment
Please, Sign In to add comment