#include <bits/stdc++.h>
using namespace std;
long long n, q, nom, it, flag, a, b, res;
string s[107], r;
void solve1()
{
cin>>s[0];
s[0]='&'+s[0];
nom=0;
while(q--)
{
cin>>r;
if(r[0]=='t')
{
cin>>it;
nom++;
s[nom]=s[nom-1];
if(s[nom][it]=='0') s[nom][it]='1';
else s[nom][it]='0';
continue;
}
cin>>a>>b;
res=0;
for(int k=0; k<=nom; k++)
{
flag=0;
for(int i=a; i<b; i++)
{
if(s[k][i]=='0')
{
flag=1;
break;
}
}
if(flag==0) res++;
}
nom++;
s[nom]=s[nom-1];
cout<<res<<endl;
}
return;
}
void solve2()
{
string s, r;
long long a, b, it;
vector<long long> lst, ans;
lst.resize(n+7);
ans.resize(n+7);
cin>>s;
s='&'+s;
for(int i=1; i<=n; i++) lst[i]=0;
for(int i=1; i<=n; i++)
{
cin>>r;
if(r[0]=='t')
{
cin>>it;
if(s[it]=='1') ans[it]+=i-lst[it];
if(s[it]=='1') s[it]='0';
else s[it]='1';
lst[it]=i;
continue;
}
cin>>a>>b;
if(s[a]=='1') ans[a]+=i-lst[a];
lst[a]=i;
cout<<ans[a]<<endl;
}
return;
}
int main()
{
cin>>n>>q;
if(n<=100 && q<=100) solve1();
else solve2();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |