#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
cin>>n>>q;
string s;
cin>>s;
int pre[n+1],ans[n][n+1]={};
pre[0]=0;
for (int i=0;i<n;i++)
pre[i+1]=pre[i]+(s[i]-'0');
for (int i=0;i<n;i++)
for (int j=i+1;j<=n;j++)
ans[i][j]=(pre[j]-pre[i]==j-i);
while (q--)
{
string t;
cin>>t;
if (t=="query")
{
int a,b;
cin>>a>>b;
cout<<ans[a-1][b-1]<<endl;
}
else
{
int i;
cin>>i;
s[i-1]=char('0'+1-(s[i-1]-'0'));
}
pre[0]=0;
for (int i=0;i<n;i++)
pre[i+1]=pre[i]+(s[i]-'0');
for (int i=0;i<n;i++)
for (int j=i+1;j<=n;j++)
ans[i][j]+=(pre[j]-pre[i]==j-i);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1297 ms |
1236 KB |
Output is correct |
2 |
Execution timed out |
5069 ms |
1076 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
4188 KB |
Output is correct |
2 |
Correct |
367 ms |
4184 KB |
Output is correct |
3 |
Correct |
406 ms |
4188 KB |
Output is correct |
4 |
Correct |
376 ms |
4184 KB |
Output is correct |
5 |
Runtime error |
263 ms |
524288 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
381 ms |
4188 KB |
Output is correct |
2 |
Correct |
388 ms |
4188 KB |
Output is correct |
3 |
Correct |
377 ms |
4332 KB |
Output is correct |
4 |
Correct |
413 ms |
4188 KB |
Output is correct |
5 |
Runtime error |
253 ms |
524288 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1297 ms |
1236 KB |
Output is correct |
9 |
Execution timed out |
5069 ms |
1076 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |