#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)
using namespace std;
ll fp(ll x , ll y)
{
if(y==0)
return 1;
ll z = fp(x,y/2);
if(y&1)
return z*z%mod*x%mod;
else
return z*z%mod;
}
int sqrot(ll x)
{
int l = 0 , r = INT_MAX;
while(l<=r)
{
if(mid*mid>=x)
r=mid-1;
else
l=mid+1;
}
return r+1;
}
ll cel(ll x , ll y)
{
return x/y + bool(x%y);
}
bool s[300009];
set<pll> seg[2000009];
ll sum[2000009];
void se(ll n , ll l , ll r , ll idx , ll val1 , ll val2)
{
if(l>idx||r<idx)
return;
seg[n].in({val1,val2});
if(l!=r)
{
se(lc,l,mid,idx,val1,val2);
se(rc,mid+1,r,idx,val1,val2);
}
}
ll sg(ll n , ll l , ll r , ll l1 , ll r1 , ll idx)
{
if(l>r1||r<l1)
return 1e10;
if(l>=l1&&r<=r1)
{
auto it = seg[n].lower_bound({idx,0});
ll x = 1e10;
if(it!=seg[n].end())
x=it->S;
return x;
}
return min(sg(lc,l,mid,l1,r1,idx),sg(rc,mid+1,r,l1,r1,idx));
}
void sume(ll n , ll l , ll r , ll idx , ll val)
{
if(l>idx||r<idx)
return;
if(l==r)
{
sum[n]=val;
return;
}
sume(lc,l,mid,idx,val);
sume(rc,mid+1,r,idx,val);
sum[n]=sum[lc]+sum[rc];
}
ll sumr(ll n , ll l , ll r , ll l1 , ll r1)
{
if(l>r1||r<l1)
return 1e10;
if(l==r)
{
if(sum[n]==0)
return l;
else
return 1e10;
}
if(l>=l1&&r<=r1)
{
if(sum[lc]==mid-l+1)
return sumr(rc,mid+1,r,l1,r1);
else
return sumr(lc,l,mid,l1,r1);
}
ll e = sumr(lc,l,mid,l1,r1);
if(e==1e10)
e=sumr(rc,mid+1,r,l1,r1);
return e;
}
ll suml(ll n , ll l , ll r , ll l1 , ll r1)
{
//cout << l << " " << r << "\n";
if(l>r1||r<l1)
return 1e10;
if(l==r)
{
if(sum[n]==0)
return l;
else
return 1e10;
}
if(l>=l1&&r<=r1)
{
if(sum[rc]==mid-l+1)
return suml(lc,l,mid,l1,r1);
else
return suml(rc,mid+1,r,l1,r1);
}
ll e = suml(rc,mid+1,r,l1,r1);
if(e==1e10)
e=suml(lc,l,mid,l1,r1);
return e;
}
int main()
{
d3
ll n , q;
cin >> n >> q;
string s1;
cin >> s1;
for(int i = 0 ; n>i ; i++)
{
if(s1[i]=='0')
s[i+1]=0;
else
{
sume(1,1,n,i+1,1);
s[i+1]=1;
}
}
for(int i = 1 ; n>=i ; i++)
{
if(s[i]==1)
{
ll j = i;
for(;n>=j;j++)
{
if(s[j]==0)
break;
}
se(1,1,n+1,i,j,0);
i=j;
}
}
for(int h = 1 ; q>=h ; h++)
{
string t;
cin >> t;
if(t[0]=='q')
{
ll a , b;
cin >> a >> b;
ll e = sg(1,1,n+1,1,a,b);
ll ans = h-e;
if(ans<0)
ans=0;
cans
}
else
{
ll x;
cin >> x;
sume(1,1,n,x,1);
ll r1 = sumr(1,1,n,x+1,n);
if(r1==1e10)
r1=n+1;
ll l1 = suml(1,1,n,1,x-1)+1;
if(l1==1e10+1)
l1=1;
//cout << l1 << " " << r1 << "\n";
se(1,1,n+1,l1,r1,h);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
95492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
493 ms |
171604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
96092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
95576 KB |
Output is correct |
2 |
Incorrect |
21 ms |
95836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
95492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |