Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem link :
- //done by sanath kumar
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define ld long double
- #define mod 1000000007
- #define inf 1e9
- #define endl "\n"
- #define pb push_back
- #define vi vector<ll>
- #define vs vector<string>
- #define pii pair<ll,ll>
- #define ump unordered_map
- #define mp make_pair
- #define pq_max priority_queue<ll>
- #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
- #define all(v) v.begin(),v.end()
- #define ff first
- #define ss second
- #define mid(l,r) (l+(r-l))/2
- #define bitc(x) __builtin_popcount(x)
- #define loop(i,a,b) for(int i=(a);i<=(b);i++)
- #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
- #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
- #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
- #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
- template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
- template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
- void err(istream_iterator<string> it){}
- template<typename T,typename... Args>
- void err(istream_iterator<string> it,T a,Args... args){
- cout<<*it<<" = "<<a<<endl;
- err(++it,args...);
- }
- void file_i_o(){
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- }
- void update(int arr[],int sum[][11],int lazy[],int n,int b,int l,int r,int y,int x){
- int bnl=l/b,bnr=r/b;
- loop(i,0,10){
- sum[bnl][i]=0;
- sum[bnr][i]=0;
- }
- for(int i=l;i<=r and i<(bnl+1)*b;i++){
- arr[i]=(arr[i]+y)%x;
- }
- for(int i=bnl*b;i<n and i<(bnl+1)*b;i++) sum[bnl][arr[i]]++;
- if(bnl!=bnr){
- for(int i=bnr*b;i<=r;i++){
- arr[i]=(arr[i]+y)%x;
- }
- for(int i=bnr*b;i<n and i<(bnr+1)*b;i++) sum[bnr][arr[i]]++;
- for(int i=bnl+1;i<=bnr-1;i++){
- lazy[i]+=y;
- }
- }
- }
- int query(int arr[],int sum[][11],int lazy[],int n,int b,int l,int r,int x){
- int bnl=l/b,bnr=r/b,ans=0;
- for(int i=l;i<=r and i<(bnl+1)*b;i++){
- if((arr[i]+lazy[bnl])%x==0){
- ans++;
- }
- }
- if(bnl!=bnr){
- for(int i=bnr*b;i<=r;i++){
- if((arr[i]+lazy[bnr])%x==0){
- ans++;
- }
- }
- for(int i=bnl+1;i<=bnr-1;i++){
- ans+=sum[i][(x-lazy[i])%x];
- }
- }
- return ans;
- }
- int main(){
- file_i_o();
- clock_t begin=clock();
- int n,q,x;
- cin>>n>>q>>x;
- int B[n];
- int arr[n];
- loop(i,0,n-1) cin>>B[i];
- loop(i,0,n-1){
- arr[i]=B[i]%x;
- }
- int b=sqrt(n);
- int sum[(n/b)+1][11],lazy[(n/b)+1];
- loop(i,0,(n/b)){
- lazy[i]=0;
- loop(j,0,x-1){
- sum[i][j]=0;
- }
- }
- for(int i=0;i<=(n/b);i++){
- for(int j=i*b;j<(i+1)*b and j<n;j++){
- sum[i][arr[j]]++;
- }
- }
- while(q--){
- int type;
- cin>>type;
- if(type==1){
- int l,r,y;
- cin>>l>>r>>y;
- l--,r--;
- update(arr,sum,lazy,n,b,l,r,y%x,x);
- }
- else{
- int l,r;
- cin>>l>>r;
- l--;r--;
- cout<<query(arr,sum,lazy,n,b,l,r,x)<<endl;
- }
- }
- #ifndef ONLINE_JUDGE
- clock_t end=clock();
- cout<<"\n\n\nExecuted in :"<<double(end-begin)/CLOCKS_PER_SEC*1000<<" ms"<<endl;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment