fork download
  1. //Lib
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<ctime>
  7.  
  8. #include<iostream>
  9. #include<algorithm>
  10. #include<vector>
  11. #include<string>
  12. #include<queue>
  13. #include<stack>
  14. #include<set>
  15. #include<map>
  16. using namespace std;
  17. //Macro
  18. #define rep(i,a,b) for(int i=a,tt=b;i<=tt;++i)
  19. #define drep(i,a,b) for(int i=a,tt=b;i>=tt;--i)
  20. #define erep(i,e,x) for(int i=x;i;i=e[i].next)
  21. #define irep(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
  22. #define read() (strtol(ipos,&ipos,10))
  23. #define sqr(x) ((x)*(x))
  24. #define pb push_back
  25. #define PS system("pause");
  26. typedef long long ll;
  27. typedef pair<int,int> pii;
  28. const int oo=~0U>>1;
  29. const double inf=1e100;
  30. const double eps=1e-6;
  31. string name="", in=".in", out=".out";
  32. //Var
  33. struct info
  34. {
  35. int m,lm,rm,sum,size;
  36. info():size(1){}
  37. void set(bool x){m=lm=rm=sum=x?size:0;}
  38. const bool full()const{return size==sum;}
  39. friend info operator +(const info &a,const info &b)
  40. {
  41. info c;
  42. c.size=a.size+b.size;
  43. c.sum=a.sum+b.sum;
  44. c.lm=a.full()?a.sum+b.lm:a.lm;
  45. c.rm=b.full()?b.sum+a.rm:b.rm;
  46. c.m=max(max(a.m,b.m),a.rm+b.lm);
  47. return c;
  48. }
  49. };
  50. struct T
  51. {
  52. #define lc(x) (x<<1)
  53. #define rc(x) (x<<1^1)
  54. info c[2];bool exist;
  55. T(bool f=true):exist(f){}
  56. void set(bool color){rep(i,0,1)c[i].set(i==color);}
  57. friend T operator +(const T &a,const T &b)
  58. {
  59. if(!a.exist)return b;if(!b.exist)return a;
  60. T c;rep(i,0,1)c.c[i]=a.c[i]+b.c[i];
  61. return c;
  62. }
  63. }tree[262145];
  64. int num[100008],flag[262145],n,m;
  65. void Set(int root,int delta)
  66. {
  67. if(delta==3){swap(tree[root].c[0],tree[root].c[1]);flag[root]=3-flag[root];}
  68. else{tree[root].set(delta-1);flag[root]=delta;}
  69. }
  70. void Push_Down(int root)
  71. {
  72. if(flag[root])Set(lc(root),flag[root]),Set(rc(root),flag[root]),flag[root]=0;
  73. }
  74. void Change(int root,int l,int r,int a,int b,int delta)
  75. {
  76. if(a>r||b<l)return;
  77. if(a<=l&&r<=b){Set(root,delta);return;}
  78. Push_Down(root);
  79. Change(lc(root),l,l+r>>1,a,b,delta);Change(rc(root),(l+r>>1)+1,r,a,b,delta);
  80. tree[root]=tree[lc(root)]+tree[rc(root)];
  81. }
  82. T Get(int root,int l,int r,int a,int b)
  83. {
  84. if(a>r||b<l)return T(false);
  85. if(a<=l&&r<=b)return tree[root];
  86. Push_Down(root);
  87. return Get(lc(root),l,l+r>>1,a,b)+Get(rc(root),(l+r>>1)+1,r,a,b);
  88. }
  89. void Build(int root,int l,int r)
  90. {
  91. if(l==r){tree[root].set(num[l]);return;}
  92. Build(lc(root),l,l+r>>1);
  93. Build(rc(root),(l+r>>1)+1,r);
  94. tree[root]=tree[lc(root)]+tree[rc(root)];
  95. }
  96. void Work()
  97. {
  98. int o,a,b;
  99. scanf("%d%d",&n,&m);
  100. rep(i,1,n)scanf("%d",num+i);
  101. Build(1,1,n);
  102. rep(i,1,m)
  103. {
  104. scanf("%d%d%d",&o,&a,&b);a++;b++;
  105. switch(o)
  106. {
  107. case 0:Change(1,1,n,a,b,1);break;
  108. case 1:Change(1,1,n,a,b,2);break;
  109. case 2:Change(1,1,n,a,b,3);break;
  110. case 3:printf("%d\n",Get(1,1,n,a,b).c[1].sum);break;
  111. case 4:printf("%d\n",Get(1,1,n,a,b).c[1].m);break;
  112. }
  113. }
  114. }
  115. int main()
  116. {
  117. // freopen((name+in).c_str(),"r",stdin);
  118. // freopen((name+out).c_str(),"w",stdout);
  119. // Init();
  120. Work();
  121. return 0;
  122. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty