Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * ####### # *
- * # # # ###### # # # # #### # # # # # *
- * # # # # # # ## # # # # # # # *
- * # ###### ##### # # # # # #### ###### # # # *
- * # # # # ####### # # # # # # # # # *
- * # # # # # # # ## # # # # # # # *
- * # # # ###### # # # # #### # # #### ###### *
- ***************************************************************************/
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define endl '\n'
- #define pii pair<ll int,ll int>
- #define vi vector<ll int>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll int)x.size()
- #define hell 1000000007
- #define rep(i,a,b) for(ll int i=a;i<b;i++)
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define bs binary_search
- #define mp make_pair
- using namespace std;
- #define N 2000005
- ll tree[5*N];
- bool lazy[5*N];
- bool a[N];
- void build(ll node,ll start,ll end)
- {
- if(start==end)
- {
- tree[node]=a[start];
- return;
- }
- ll mid = (start+end)/2;
- build(2*node,start,mid);
- build(2*node+1,mid+1,end);
- tree[node]=tree[2*node]+tree[2*node+1];
- return;
- }
- void update(ll node,ll start,ll end,ll l,ll r)
- {
- if(start>end || l>r || l>end || r<start)
- return;
- if(lazy[node])
- {
- tree[node]=(end-start+1)-tree[node];
- if(start!=end)
- {
- lazy[2*node]=1;
- lazy[2*node+1]=1;
- }
- lazy[node]=0;
- }
- if(l<=start && r>=end)
- {
- tree[node]=(end-start+1)-tree[node];
- if(start!=end)
- {
- lazy[2*node]=1;
- lazy[2*node+1]=1;
- }
- lazy[node]=0;
- return;
- }
- ll mid=(start+end)/2;
- update(2*node,start,mid,l,r);
- update(2*node+1,mid+1,end,l,r);
- tree[node]=tree[2*node]+tree[2*node+1];
- return;
- }
- ll query(ll node,ll start,ll end,ll l,ll r)
- {
- if(start>end || l>r || l>end || r<start)
- return 0;
- if(lazy[node])
- {
- tree[node]=(end-start+1)-tree[node];
- if(start!=end)
- {
- lazy[2*node]=1;
- lazy[2*node+1]=1;
- }
- lazy[node]=0;
- }
- if(l<=start && r>=end)
- {
- return tree[node];
- }
- ll mid=(start+end)/2;
- ll p=query(2*node,start,mid,l,r);
- p+=query(2*node+1,mid+1,end,l,r);
- return p;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int TESTS=1;
- // cin>>TESTS;
- while(TESTS--)
- {
- ll n,m;
- cin>>n>>m;
- string s;
- cin>>s;
- rep(i,1,n)
- {
- if(s[i-1]=='>')
- a[i]=0;
- else
- a[i]=1;
- }
- ll t,x,y;
- n--;
- build(1,1,n);
- // rep(i,1,n+1)
- // cout<<a[i]<<" ";
- // cout<<endl;
- // rep(i,1,4*n)
- // cout<<tree[i]<<" ";
- // cout<<endl;
- rep(i,0,m)
- {
- cin>>t>>x>>y;
- if(t==1)
- {
- // if(x==y)
- // cout<<"fuck";
- update(1,1,n,x,y-1);
- }
- else
- {
- if(y>x)
- cout<<query(1,1,n,x,y-1)<<endl;
- else
- cout<<((x-y)-query(1,1,n,y,x-1))<<endl;
- // if(x==y)
- // cout<<"fuck";
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement