# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
204710 | 2020-02-26T18:27:15 Z | luciocf | Simple game (IZhO17_game) | C++14 | 100 ms | 6904 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6+10; int n, m; int a[maxn]; int bit[maxn]; void upd(int x, int v) { for (; x < maxn; x += (x&-x)) bit[x] += v; } int soma(int x) { int ans = 0; for (; x > 0; x -= (x&-x)) ans += bit[x]; return ans; } void range_upd(int l, int r, int x) { upd(l, x); upd(r+1, -x); } int main(void) { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) { if (a[i] <= a[i+1]) range_upd(a[i], a[i+1]-1, 1); else range_upd(a[i+1]+1, a[i], 1); } for (int i = 1; i <= m; i++) { int op; scanf("%d", &op); if (op == 1) { int pos, v; scanf("%d %d", &pos, &v); if (pos != 1) { if (a[pos-1] <= a[pos]) range_upd(a[pos-1], a[pos]-1, -1); else range_upd(a[pos]+1, a[pos-1], -1); if (a[pos-1] <= v) range_upd(a[pos-1], v-1, 1); else range_upd(v+1, a[pos-1], 1); } if (pos != n) { if (a[pos] <= a[pos+1]) range_upd(a[pos], a[pos+1]-1, -1); else range_upd(a[pos+1]+1, a[pos], -1); if (v <= a[pos+1]) range_upd(v, a[pos+1]-1, 1); else range_upd(a[pos+1]+1, v, 1); } a[pos] = v; } else { int H; scanf("%d", &H); printf("%d\n", (H == a[n] ? soma(H)+1 : soma(H))); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 7 ms | 3960 KB | Output is correct |
3 | Correct | 7 ms | 3960 KB | Output is correct |
4 | Correct | 8 ms | 3836 KB | Output is correct |
5 | Correct | 7 ms | 3832 KB | Output is correct |
6 | Correct | 7 ms | 3960 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 7 ms | 3960 KB | Output is correct |
3 | Correct | 7 ms | 3960 KB | Output is correct |
4 | Correct | 8 ms | 3836 KB | Output is correct |
5 | Correct | 7 ms | 3832 KB | Output is correct |
6 | Correct | 7 ms | 3960 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 58 ms | 1784 KB | Output is correct |
9 | Correct | 77 ms | 6904 KB | Output is correct |
10 | Correct | 80 ms | 6904 KB | Output is correct |
11 | Correct | 58 ms | 1656 KB | Output is correct |
12 | Correct | 66 ms | 2912 KB | Output is correct |
13 | Correct | 65 ms | 2808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 7 ms | 3960 KB | Output is correct |
3 | Correct | 7 ms | 3960 KB | Output is correct |
4 | Correct | 8 ms | 3836 KB | Output is correct |
5 | Correct | 7 ms | 3832 KB | Output is correct |
6 | Correct | 7 ms | 3960 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 58 ms | 1784 KB | Output is correct |
9 | Correct | 77 ms | 6904 KB | Output is correct |
10 | Correct | 80 ms | 6904 KB | Output is correct |
11 | Correct | 58 ms | 1656 KB | Output is correct |
12 | Correct | 66 ms | 2912 KB | Output is correct |
13 | Correct | 65 ms | 2808 KB | Output is correct |
14 | Correct | 93 ms | 6904 KB | Output is correct |
15 | Correct | 95 ms | 6904 KB | Output is correct |
16 | Correct | 92 ms | 6796 KB | Output is correct |
17 | Correct | 95 ms | 6904 KB | Output is correct |
18 | Correct | 100 ms | 6904 KB | Output is correct |