#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, nq, a[N], pre;
set <int> s;
vector <int> vt[N], bit[N];
struct ngu {
int a, b, c, d, e, f, g;
}; vector <ngu> task;
void upd(int x, int _y, int last, int i) {
while (x) {
int y = lower_bound(vt[x].begin(), vt[x].end(), _y) - vt[x].begin();
while (y < vt[x].size()) {
bit[x][y] += (i ? last : -last);
y += (y & -y);
}
x -= (x & -x);
}
}
void up(int x, int y, int u, int v, int last, int i) {
upd(x, y, last, i);
upd(x, v + 1, last, 1 - i);
upd(u - 1, y, last, 1 - i);
upd(u - 1, v + 1, last, i);
}
void fake_up(int x, int y, int u, int v, int last, int i) {
task.push_back({0, x, y, u, v, last, i});
while (x) {
vt[x].push_back(y);
vt[x].push_back(v + 1);
x -= (x & -x);
}
x = u - 1;
while (x ) {
vt[x].push_back(y);
vt[x].push_back(v + 1);
x -= (x & -x);
}
}
int get(int x, int _y) {
int ret = 0;
while (x <= n) {
int y = lower_bound(vt[x].begin(), vt[x].end(), _y) - vt[x].begin();
while (y) {
ret += bit[x][y];
y -= (y & -y);
}
x += (x & -x);
}
return ret;
}
main () {
cin.tie(0)->sync_with_stdio(0);
if(fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("wa.out", "w", stdout);
}
cin >> n >> nq; n++;
for(int i = 1; i < n; i++) {
char ch; cin >> ch;
a[i] = ch - '0';
if(!a[i]) {
s.insert(i);
fake_up(n, pre + 1, i + 1, i, 0, 0);
pre = i;
}
}
s.insert(0); s.insert(n);
for(int t = 1; t <= nq; t++) {
string str; cin >> str;
if(str == "query") {
int u, v; cin >> u >> v;
if(u < v) swap(u, v);
if(*s.lower_bound(v) < u) task.push_back({1, 0, u, v, 0, 0, 0});
else task.push_back({1, t, u, v, 0, 0, 0});
while (u <= n) {
vt[u].push_back(v);
u += (u & -u);
}
}
else {
int i; cin >> i;
a[i] = 1 - a[i];
if(!a[i]) s.insert(i);
else s.erase(i);
int j = *(--(s.lower_bound(i)));
int k = *s.upper_bound(i);
fake_up(k, j + 1, i + 1, i, t, a[i]);
}
}
for(int i = 1; i <= n; i++) {
vt[i].push_back(-1);
sort(vt[i].begin(), vt[i].end());
vt[i].resize(unique(vt[i].begin(), vt[i].end()) - vt[i].begin());
bit[i].resize(vt[i].size());
}
for(auto [type, x, y, u, v, last, i] : task) {
if(type) cout << x - get(y, u) << "\n";
else up(x, y, u, v, last, i);
}
}
Compilation message
street_lamps.cpp: In function 'void upd(int, int, int, int)':
street_lamps.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | while (y < vt[x].size()) {
| ~~^~~~~~~~~~~~~~
street_lamps.cpp: At global scope:
street_lamps.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main () {
| ^~~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen("task.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen("wa.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14332 KB |
Output is correct |
4 |
Correct |
8 ms |
14372 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
10 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
273 ms |
40332 KB |
Output is correct |
2 |
Correct |
355 ms |
44736 KB |
Output is correct |
3 |
Correct |
630 ms |
52560 KB |
Output is correct |
4 |
Correct |
2547 ms |
124596 KB |
Output is correct |
5 |
Correct |
2496 ms |
107028 KB |
Output is correct |
6 |
Correct |
2950 ms |
128888 KB |
Output is correct |
7 |
Correct |
2603 ms |
154484 KB |
Output is correct |
8 |
Correct |
1012 ms |
63388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14804 KB |
Output is correct |
2 |
Correct |
13 ms |
14676 KB |
Output is correct |
3 |
Correct |
13 ms |
14676 KB |
Output is correct |
4 |
Correct |
11 ms |
14548 KB |
Output is correct |
5 |
Correct |
4040 ms |
174200 KB |
Output is correct |
6 |
Correct |
3139 ms |
146992 KB |
Output is correct |
7 |
Correct |
2134 ms |
106824 KB |
Output is correct |
8 |
Correct |
928 ms |
64984 KB |
Output is correct |
9 |
Correct |
116 ms |
26292 KB |
Output is correct |
10 |
Correct |
127 ms |
33544 KB |
Output is correct |
11 |
Correct |
137 ms |
34220 KB |
Output is correct |
12 |
Correct |
2516 ms |
157688 KB |
Output is correct |
13 |
Correct |
1010 ms |
64924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14628 KB |
Output is correct |
2 |
Correct |
11 ms |
14676 KB |
Output is correct |
3 |
Correct |
12 ms |
14684 KB |
Output is correct |
4 |
Correct |
13 ms |
14684 KB |
Output is correct |
5 |
Correct |
1838 ms |
111748 KB |
Output is correct |
6 |
Correct |
2140 ms |
121392 KB |
Output is correct |
7 |
Correct |
2417 ms |
129872 KB |
Output is correct |
8 |
Correct |
2909 ms |
149608 KB |
Output is correct |
9 |
Correct |
412 ms |
50696 KB |
Output is correct |
10 |
Correct |
338 ms |
46836 KB |
Output is correct |
11 |
Correct |
416 ms |
50908 KB |
Output is correct |
12 |
Correct |
326 ms |
46984 KB |
Output is correct |
13 |
Correct |
401 ms |
51080 KB |
Output is correct |
14 |
Correct |
378 ms |
46808 KB |
Output is correct |
15 |
Correct |
2478 ms |
157200 KB |
Output is correct |
16 |
Correct |
948 ms |
64724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14332 KB |
Output is correct |
4 |
Correct |
8 ms |
14372 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
10 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14420 KB |
Output is correct |
8 |
Correct |
273 ms |
40332 KB |
Output is correct |
9 |
Correct |
355 ms |
44736 KB |
Output is correct |
10 |
Correct |
630 ms |
52560 KB |
Output is correct |
11 |
Correct |
2547 ms |
124596 KB |
Output is correct |
12 |
Correct |
2496 ms |
107028 KB |
Output is correct |
13 |
Correct |
2950 ms |
128888 KB |
Output is correct |
14 |
Correct |
2603 ms |
154484 KB |
Output is correct |
15 |
Correct |
1012 ms |
63388 KB |
Output is correct |
16 |
Correct |
14 ms |
14804 KB |
Output is correct |
17 |
Correct |
13 ms |
14676 KB |
Output is correct |
18 |
Correct |
13 ms |
14676 KB |
Output is correct |
19 |
Correct |
11 ms |
14548 KB |
Output is correct |
20 |
Correct |
4040 ms |
174200 KB |
Output is correct |
21 |
Correct |
3139 ms |
146992 KB |
Output is correct |
22 |
Correct |
2134 ms |
106824 KB |
Output is correct |
23 |
Correct |
928 ms |
64984 KB |
Output is correct |
24 |
Correct |
116 ms |
26292 KB |
Output is correct |
25 |
Correct |
127 ms |
33544 KB |
Output is correct |
26 |
Correct |
137 ms |
34220 KB |
Output is correct |
27 |
Correct |
2516 ms |
157688 KB |
Output is correct |
28 |
Correct |
1010 ms |
64924 KB |
Output is correct |
29 |
Correct |
12 ms |
14628 KB |
Output is correct |
30 |
Correct |
11 ms |
14676 KB |
Output is correct |
31 |
Correct |
12 ms |
14684 KB |
Output is correct |
32 |
Correct |
13 ms |
14684 KB |
Output is correct |
33 |
Correct |
1838 ms |
111748 KB |
Output is correct |
34 |
Correct |
2140 ms |
121392 KB |
Output is correct |
35 |
Correct |
2417 ms |
129872 KB |
Output is correct |
36 |
Correct |
2909 ms |
149608 KB |
Output is correct |
37 |
Correct |
412 ms |
50696 KB |
Output is correct |
38 |
Correct |
338 ms |
46836 KB |
Output is correct |
39 |
Correct |
416 ms |
50908 KB |
Output is correct |
40 |
Correct |
326 ms |
46984 KB |
Output is correct |
41 |
Correct |
401 ms |
51080 KB |
Output is correct |
42 |
Correct |
378 ms |
46808 KB |
Output is correct |
43 |
Correct |
2478 ms |
157200 KB |
Output is correct |
44 |
Correct |
948 ms |
64724 KB |
Output is correct |
45 |
Correct |
108 ms |
25640 KB |
Output is correct |
46 |
Correct |
187 ms |
29612 KB |
Output is correct |
47 |
Correct |
1103 ms |
63208 KB |
Output is correct |
48 |
Correct |
2469 ms |
125768 KB |
Output is correct |
49 |
Correct |
146 ms |
33892 KB |
Output is correct |
50 |
Correct |
139 ms |
33172 KB |
Output is correct |
51 |
Correct |
156 ms |
34032 KB |
Output is correct |
52 |
Correct |
169 ms |
34580 KB |
Output is correct |
53 |
Correct |
173 ms |
34528 KB |
Output is correct |
54 |
Correct |
164 ms |
34612 KB |
Output is correct |