Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <string.h>
- using namespace std;
- int n,m;
- int tree[20*100010][2];
- int needsUp[20*100010];
- int qVec[3];
- inline void shift(int root,int l, int r, int qtd) {
- int v1=tree[root][0];
- int v2=tree[root][1];
- int v0=(r-l+1)-v1-v2;
- if (qtd==1) {
- tree[root][0]=v0;
- tree[root][1]=v1;
- }
- else
- if (qtd==2) {
- tree[root][0]=v2;
- tree[root][1]=v0;
- }
- }
- inline void propagate(int root, int l, int r) {
- shift(root,l,r,needsUp[root]);
- if (l<r) {
- needsUp[2*root+1]+=needsUp[root];
- if (needsUp[2*root+1]>=3) needsUp[2*root+1]-=3;
- needsUp[2*root+2]+=needsUp[root];
- if (needsUp[2*root+2]>=3) needsUp[2*root+2]-=3;
- }
- needsUp[root]=0;
- }
- void update(int root, int l, int r, int ql, int qr) {
- if (ql<=l && qr>=r) {
- shift(root,l,r,1);
- if (l<r) {
- needsUp[2*root+1]++;
- if (needsUp[2*root+1]>=3) needsUp[2*root+1]-=3;
- needsUp[2*root+2]++;
- if (needsUp[2*root+2]>=3) needsUp[2*root+2]-=3;
- }
- return;
- }
- int mid=(l+r)/2;
- if (ql<=mid) update(2*root+1,l,mid,ql,min(qr,mid));
- if (qr>mid) update(2*root+2,mid+1,r,max(mid+1,ql),qr);
- propagate(2*root+1,l,mid);
- propagate(2*root+2,mid+1,r);
- tree[root][0]=tree[2*root+1][0]+tree[2*root+2][0];
- tree[root][1]=tree[2*root+1][1]+tree[2*root+2][1];
- }
- void query(int root, int l, int r, int ql, int qr) {
- propagate(root,l,r);
- if (ql<=l && qr>=r) {
- qVec[1]+=tree[root][0];
- qVec[2]+=tree[root][1];
- return;
- }
- int mid=(l+r)/2;
- if (ql<=mid) query(2*root+1,l,mid,ql,min(qr,mid));
- if (qr>mid) query(2*root+2,mid+1,r,max(mid+1,ql),qr);
- }
- int main() {
- while (scanf("%d %d", &n,&m)!=EOF) {
- memset(tree,0,sizeof(tree));
- memset(needsUp,0,sizeof(needsUp));
- for (int i=0; i<m; i++) {
- char c; int a,b;
- scanf(" %c %d %d", &c,&a,&b);
- a--, b--;
- if (c=='M')
- update(0,0,n-1,a,b);
- else {
- qVec[1]=qVec[2]=0;
- query(0,0,n-1,a,b);
- qVec[0]=(b-a+1)-qVec[1]-qVec[2];
- printf("%d %d %d\n", qVec[0],
- qVec[1], qVec[2]);
- }
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement