# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
209223 | 2020-03-13T12:44:45 Z | mieszko11b | 가로등 (APIO19_street_lamps) | C++14 | 249 ms | 15096 KB |
#include <bits/stdc++.h> using namespace std; int n, q; char c[107][107]; int before[300007], last0[300007]; char cc[300007]; int a[300007], b[300007]; int d[1200007]; int lv; void insert(int w, int x) { w += lv; d[w] = x; w /= 2; while(w) { d[w] = max(d[2 * w], d[2 * w + 1]); w /= 2; } } int query(int a, int b) { if(a > b) return 1e9; int va = a +lv; int vb = b + lv; int res = max(d[va], d[vb]); while(va / 2 != vb/ 2) { if(va % 2 == 0) res = max(res, d[va + 1]); if(vb % 2 == 1) res = max(res, d[vb - 1]); va /= 2; vb /= 2; } return res; } int main() { scanf("%d%d", &n, &q); if(n <= 100 && q <= 100) { scanf(" %s", c[0] + 1); for(int i = 1 ; i <= q ; i++) { char comm[10]; for(int j = 1 ; j <= n ; j++) c[i][j] = c[i - 1][j]; scanf(" %s", comm); if(comm[0] == 'q') { int a, b; scanf("%d%d", &a, &b); int res = 0; for(int j = 0 ; j < i ; j++) { bool ok = true; for(int k = a ; k < b ; k++) if(c[j][k] == '0') ok = false; if(ok) res++; } printf("%d\n", res); } else { int w; scanf("%d", &w); if(c[i][w] == '0') c[i][w] = '1'; else c[i][w] = '0'; } } return 0; } scanf(" %s", cc + 1); bool kosno = true; for(int i = 1 ; i <= q ; i++) { char comm[10]; scanf(" %s", comm); if(comm[0] == 'q') { int a, b; scanf("%d%d", &a, &b); ::a[i] = a; ::b[i] = b; if(b != a + 1) kosno = false; } else { int w; scanf("%d", &w); ::a[i] = -1; ::b[i] = w; } } if(kosno) { memset(last0, -1, sizeof last0); for(int i = 1 ; i <= q ; i++) { if(a[i] != -1) { int a = ::a[i]; int b = ::b[i]; int res = before[a]; if(cc[a] == '1') res += i - last0[a] - 1; printf("%d\n", res); } else { int w = b[i]; if(cc[w] == '1') { before[w] += i - last0[w] - 1; cc[w] = '0'; } else { last0[w] = i - 1; cc[w] = '1'; } } } return 0; } lv = 2; while(lv < n + 2) lv *= 2; for(int i = 1 ; i < 2 * lv ; i++) d[i] = 1e9; for(int i = 1 ; i <= n ; i++) if(cc[i] == '1') insert(i, 0); for(int i = 1 ; i <= q ; i++) { if(a[i] != -1) { int a = ::a[i]; int b = ::b[i]; int q = query(a, b - 1); printf("%d\n", max(0, i - q)); } else { int w = b[i]; insert(w, i); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 4 ms | 380 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 4728 KB | Output is correct |
2 | Correct | 121 ms | 4856 KB | Output is correct |
3 | Correct | 121 ms | 4856 KB | Output is correct |
4 | Correct | 139 ms | 6012 KB | Output is correct |
5 | Correct | 150 ms | 5112 KB | Output is correct |
6 | Correct | 127 ms | 6008 KB | Output is correct |
7 | Correct | 166 ms | 4932 KB | Output is correct |
8 | Correct | 161 ms | 6136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 6 ms | 376 KB | Output is correct |
5 | Correct | 118 ms | 11104 KB | Output is correct |
6 | Correct | 157 ms | 12024 KB | Output is correct |
7 | Correct | 191 ms | 12664 KB | Output is correct |
8 | Correct | 249 ms | 15096 KB | Output is correct |
9 | Correct | 113 ms | 5880 KB | Output is correct |
10 | Correct | 127 ms | 6520 KB | Output is correct |
11 | Correct | 124 ms | 6644 KB | Output is correct |
12 | Correct | 228 ms | 13560 KB | Output is correct |
13 | Correct | 249 ms | 14968 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Incorrect | 5 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 4 ms | 380 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 114 ms | 4728 KB | Output is correct |
9 | Correct | 121 ms | 4856 KB | Output is correct |
10 | Correct | 121 ms | 4856 KB | Output is correct |
11 | Correct | 139 ms | 6012 KB | Output is correct |
12 | Correct | 150 ms | 5112 KB | Output is correct |
13 | Correct | 127 ms | 6008 KB | Output is correct |
14 | Correct | 166 ms | 4932 KB | Output is correct |
15 | Correct | 161 ms | 6136 KB | Output is correct |
16 | Correct | 5 ms | 376 KB | Output is correct |
17 | Correct | 5 ms | 376 KB | Output is correct |
18 | Correct | 5 ms | 376 KB | Output is correct |
19 | Correct | 6 ms | 376 KB | Output is correct |
20 | Correct | 118 ms | 11104 KB | Output is correct |
21 | Correct | 157 ms | 12024 KB | Output is correct |
22 | Correct | 191 ms | 12664 KB | Output is correct |
23 | Correct | 249 ms | 15096 KB | Output is correct |
24 | Correct | 113 ms | 5880 KB | Output is correct |
25 | Correct | 127 ms | 6520 KB | Output is correct |
26 | Correct | 124 ms | 6644 KB | Output is correct |
27 | Correct | 228 ms | 13560 KB | Output is correct |
28 | Correct | 249 ms | 14968 KB | Output is correct |
29 | Correct | 5 ms | 376 KB | Output is correct |
30 | Incorrect | 5 ms | 376 KB | Output isn't correct |
31 | Halted | 0 ms | 0 KB | - |