// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
inline void solve() {
cin >> n >> q;
string s;
cin >> s;
s = '$' + s;
vector<vector<array<int, 2> > > upd(n + 2, vector<array<int, 2> >()); // (]
vector<array<int, 3> > que;
vector<int> tm(n + 2, 0);
for(int z = 1; z <= q; z++) {
string t;
cin >> t;
if(t == "toggle") {
int i;
cin >> i;
if(s[i] == '0') {
tm[i] = z;
s[i] = '1';
}
else {
upd[i].pb({tm[i], z});
s[i] = '0';
}
}
else {
int a, b;
cin >> a >> b;
que.pb({a, b, z});
}
}
for(int i = 1; i <= n; i++) {
if(s[i] == '1') {
upd[i].pb({tm[i], q});
}
}
// for(int i = 1; i <= n; i++) {
// cout << "i:" << i << "\n\n";
// auto &x = upd[i];
// for(auto &c : x) {
// cout << c[0] << " " << c[1] << "\n";
// }
// }
vector<vector<int> > grid(n + 3, vector<int>(q + 3, 0));
vector<int> ans(q + 1, -1);
for(int i = 1; i <= n; i++) {
for(auto c : upd[i]) {
for(int j = c[0] + 1; j <= c[1]; j++) {
grid[i][j] = 1;
}
}
}
for(auto c : que) {
ans[c[2]] = 0;
for(int t = 1; t <= c[2]; t++) {
bool f = 1;
for(int i = c[0]; i <= c[1] - 1; i++) {
if(!grid[i][t]) f = 0;
}
ans[c[2]] += f;
}
}
for(int i = 0; i <= q; i++) {
if(ans[i] == -1) continue;
cout << ans[i] << "\n";
}
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5091 ms |
251560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8284 KB |
Output is correct |
2 |
Correct |
38 ms |
8472 KB |
Output is correct |
3 |
Correct |
70 ms |
8284 KB |
Output is correct |
4 |
Correct |
117 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
191 ms |
524288 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
8284 KB |
Output is correct |
2 |
Correct |
106 ms |
8284 KB |
Output is correct |
3 |
Correct |
68 ms |
8284 KB |
Output is correct |
4 |
Correct |
9 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
201 ms |
524288 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
5091 ms |
251560 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |