We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>usingnamespacestd;#define rep(i, a, b) for(int i = a; i < b; i++)#define S(x) scanf("%d", &x)#define P(x) printf("%d\n", x)typedeflonglongintLL;intX[7]={48576,48640,49152,65536,131072,262144,524288};constintMAXN=1000001;LLBIT[MAXN];LLval;voidupdate(intidx,intval){for(inti=idx;i<MAXN;i+=i&-i)BIT[i]+=val;}LLquery(intidx){LLres=0;for(inti=idx;i;i-=i&-i)res+=BIT[i];returnres;}voidUUU(intpos,intM,intplus){rep(i,0,50){intx=pos;intcnt=999;while(x<MAXN){update(x,M);x+=x&-x;if(x>MAXN&&x!=1048576){x-=MAXN-1;cnt--;}}val+=cnt*M;pos+=plus;if(pos>1000000)pos-=1000000;}}intmain(){intQ;S(Q);while(Q--){strings;cin>>s;if(s=="U"){intpos,M,plus;scanf("%d%d%d",&pos,&M,&plus);UUU(pos,M,plus);}else{intpos1,pos2;if(val)rep(i,0,7)update(X[i],val);scanf("%d%d",&pos1,&pos2);printf("%lld\n",query(pos2)-query(pos1-1));val=0;}}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jaggu Playing with Balloons
You are viewing a single comment's thread. Return to all comments →
C++ Solution