fork(1) download
  1. /*
  2. written by- Piyush Golani
  3. language- c++
  4. country- India
  5. College- N.I.T Jamshedpur
  6. */
  7. #include <cmath>
  8. #include <ctime>
  9. #include <iostream>
  10. #include <string>
  11. #include <vector>
  12. #include<cstdio>
  13. #include<sstream>
  14. #include<algorithm>
  15. #include<cstdlib>
  16. #include<cstring>
  17. #include<map>
  18. #include<queue>
  19. #include<cctype>
  20. using namespace std;
  21. #define pb push_back
  22. #define all(s) s.begin(),s.end()
  23. #define f(i,a,b) for(int i=a;i<b;i++)
  24. #define F(i,a,b) for(int i=a;i>=b;i--)
  25. #define PI 3.1415926535897932384626433832795
  26. #define INF 2000000000
  27. #define BIG_INF 7000000000000000000LL
  28. #define mp make_pair
  29. #define eps 1e-9
  30. #define LL long long
  31. #define si(n) scanf("%d",&n)
  32. #define sll(n) scanf("%lld",&n)
  33. #define mod 1000000007
  34. #define mm 10000000
  35.  
  36. string inttostring(int n)
  37. {
  38. stringstream a;
  39. a<<n;
  40. return a.str();
  41. }
  42.  
  43. int stringtoint(string A)
  44. {
  45. istringstream a(A);
  46. int p;
  47. a>>p;
  48. return p;
  49. }
  50.  
  51. ///////////////////////////////////////////////////
  52.  
  53. int A[9999999];
  54. int flag[9999999];
  55.  
  56.  
  57.  
  58.  
  59. int update(int node, int ri, int rj, int i, int j)
  60. {
  61. if(i==ri && j==rj) {
  62. flag[node]^= 1;
  63. A[node]= rj-ri +1-A[node];
  64. return 0;
  65. }
  66. int m = (ri + rj)/2;
  67. if(j <= m) update(2*node, ri, m, i, j);
  68. else if(i > m) update(2*node+1, m+1, rj, i, j);
  69. else {
  70. update(2*node, ri, m, i, m);
  71. update(2*node+1, m+1, rj, m+1, j);
  72. }
  73. if(flag[node]) A[node]= rj-ri+1-A[2*node]-A[2*node+1];
  74. else A[node]=A[2*node]+A[2*node+1];
  75. return 0;
  76. }
  77.  
  78. int query(int node, int ri, int rj, int i, int j) {
  79. if(i==ri && j==rj) return A[node];
  80. int m = (ri + rj)/2;
  81. int ret;
  82. if(j <= m) ret = query(2*node, ri, m, i, j);
  83. else if(i > m) ret = query(2*node+1, m+1, rj, i, j);
  84. else {
  85. ret = query(2*node, ri, m, i, m);
  86. ret += query(2*node+1, m+1, rj, m+1, j);
  87. }
  88. if(flag[node]) return j-i+1-ret;
  89. return ret;
  90. }
  91.  
  92.  
  93.  
  94. int main()
  95. {
  96. int N;
  97. si(N);
  98. int Q;
  99. si(Q);
  100. int a,Aa,B;
  101. while(Q--)
  102. {
  103. si(a); si(Aa); si(B);
  104. if(a==0)
  105. {
  106. update(1,0,N-1,Aa,B);
  107. }
  108. else
  109. {
  110. int t=query(1,0,N-1,Aa,B);
  111. printf("%d\n",t);
  112. }
  113. //cout<<A[7]<<"\n";
  114. }
  115. return 0;
  116. }
Runtime error #stdin #stdout 0.03s 88896KB
stdin
Standard input is empty
stdout
Standard output is empty