This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MAX = 2e6;
ll seg[MAX],n,q,m;
ll func2(ll k)
{
return 1<<(ll)ceil(log2(k));
}
void Merge(ll ind)
{
seg[ind] = max(seg[2*ind],seg[2*ind+1]);
}
void Edit(ll val,ll loc,ll ind=1,ll l=1,ll r=n)
{
if (l == r)
{
if (l!=loc)
return ;
seg[ind] = val;
return ;
}
if (r<l || r<loc || loc<l)
return ;
ll mid = (l+r)/2;
Edit(val,loc,2*ind,l,mid);
Edit(val,loc,2*ind+1,mid+1,r);
Merge(ind);
}
ll Ask(ll a,ll b,ll ind=1,ll l=1,ll r=n)
{
if (b<l || r<a || r<l)
return -1e18;
if (a<=l && r<=b)
return seg[ind];
ll mid = (l+r)/2;
ll x = Ask(a,b,2*ind,l,mid);
ll y = Ask(a,b,2*ind+1,mid+1,r);
return max(x,y);
}
int main()
{
cin>>m>>q;
n = func2(m);
for (ll i=1; i<=2*n+2; i++)
seg[i] = -1e18;
for (ll i=1; i<=m; i++)
{
char t;
cin >> t;
if (t == '1')
Edit(0,i);
else
Edit(1e18,i);
}
ll l,r;
string s;
for (ll i=1; i<=q; i++)
{
cin>>s>>l;
if (s == "toggle")
{
ll t = Ask(l,l);
ll ed = (t==1e18 ? i : 1e18);
Edit(ed,l);
continue;
}
cin>>r;
ll a = Ask(l,r);
if (a == 1e18)
cout<<0;
else
cout<<i-a;
cout<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |