#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
617 ms |
3832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
530 ms |
11896 KB |
Output is correct |
6 |
Correct |
788 ms |
12152 KB |
Output is correct |
7 |
Incorrect |
1059 ms |
12216 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |