Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <cstring>
- using namespace std;
- vector <int> a(1000000,0);
- vector<int> t(4000000,0);
- vector<bool> lazy(4000000,false);
- void lazyu(int b, int e, int nodo, int j, int i)
- {
- int mid=(b+e)/2,l=nodo*2+1, r=l+1;
- if(lazy[nodo])
- {
- t[nodo]=b-e+1-t[nodo];
- if(b!=e)
- {
- lazy[l]=!lazy[l];
- lazy[r]=!lazy[r];
- }
- lazy[nodo]=false;
- }
- if(b>i||e<j) return;
- if(b>=j&&e<=i)
- {
- t[nodo]=e-b+1-t[nodo];
- if(b!=e)
- {
- lazy[r]=!lazy[r];
- lazy[l]=!lazy[l];
- }
- }
- else
- {
- lazyu(b,mid,l,i,j);
- lazyu(mid+1,e,r,i,j);
- t[nodo]=t[r]+t[l];
- }
- }
- int lazyq(int b, int e , int nodo, int i, int j)
- {
- if(b>j||e<i) return 0;
- int mid=(b+e)/2,l=nodo*2+1, r=l+1;
- if(lazy[nodo])
- {
- t[nodo]=e-b+1-t[nodo];
- if(b!=e)
- {
- lazy[l]=!lazy[l]; lazy[r]=!lazy[r];
- }
- lazy[nodo]=false;
- }
- if(b>=i&&e<=j)
- return t[nodo];
- return lazyq(b,mid,l,i,j)+lazyq(mid+1,e,r,i,j);
- }
- int main()
- {
- int n,m,d,x,y,a,b;
- cin>>n>>m;
- for(int i=0;i<m;i++)
- {
- cin>>d>>x>>y;
- if(d==0)
- lazyu(0,n-1,0,x-1,y-1);
- else
- cout<<lazyq(0,n-1,0,x-1,y-1)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement