Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <cstring>
  3. using namespace std;
  4. vector <int> a(1000000,0);
  5. vector<int> t(4000000,0);
  6. vector<bool> lazy(4000000,false);
  7. void lazyu(int b, int e, int nodo, int j, int i)
  8. {
  9.     int mid=(b+e)/2,l=nodo*2+1, r=l+1;
  10.     if(lazy[nodo])
  11.     {
  12.         t[nodo]=b-e+1-t[nodo];
  13.         if(b!=e)
  14.         {
  15.             lazy[l]=!lazy[l];
  16.             lazy[r]=!lazy[r];
  17.         }
  18.         lazy[nodo]=false;
  19.     }
  20.     if(b>i||e<j) return;
  21.     if(b>=j&&e<=i)
  22.     {
  23.         t[nodo]=e-b+1-t[nodo];
  24.         if(b!=e)
  25.         {
  26.             lazy[r]=!lazy[r];
  27.             lazy[l]=!lazy[l];
  28.         }
  29.     }
  30.     else
  31.     {
  32.         lazyu(b,mid,l,i,j);
  33.         lazyu(mid+1,e,r,i,j);
  34.         t[nodo]=t[r]+t[l];
  35.     }
  36.  
  37. }
  38. int lazyq(int b, int e , int nodo, int i, int j)
  39. {
  40.     if(b>j||e<i) return 0;
  41.     int mid=(b+e)/2,l=nodo*2+1, r=l+1;
  42.     if(lazy[nodo])
  43.     {
  44.         t[nodo]=e-b+1-t[nodo];
  45.         if(b!=e)
  46.         {
  47.             lazy[l]=!lazy[l]; lazy[r]=!lazy[r];
  48.         }
  49.         lazy[nodo]=false;
  50.     }
  51.  
  52.     if(b>=i&&e<=j)
  53.     return t[nodo];
  54.     return lazyq(b,mid,l,i,j)+lazyq(mid+1,e,r,i,j);
  55. }
  56. int main()
  57. {
  58.     int n,m,d,x,y,a,b;
  59.     cin>>n>>m;
  60.     for(int i=0;i<m;i++)
  61.     {
  62.         cin>>d>>x>>y;
  63.         if(d==0)
  64.         lazyu(0,n-1,0,x-1,y-1);
  65.         else
  66.         cout<<lazyq(0,n-1,0,x-1,y-1)<<endl;
  67.     }
  68.  
  69.  
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement