# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
224583 | 2020-04-18T13:00:11 Z | Nightlight | Pilot (NOI19_pilot) | C++14 | 770 ms | 55196 KB |
#include <bits/stdc++.h> #define pii pair<int, int> #define val first #define id second using namespace std; int N, K; long long sz[1000005]; int par[1000005]; pii H[1000005], Q[1000005]; bitset<1000005> done; long long ans[1000005], res; int findpar(int u) { if(par[u] == u) return u; else { par[u] = findpar(par[u]); return par[u]; } } void merge(int u, int v) { u = findpar(u); v = findpar(v); res -= (sz[u] * (sz[u] + 1)) / 2; res -= (sz[v] * (sz[v] + 1)) / 2; par[v] = u; sz[u] += sz[v]; res += ((sz[u] + 1) * sz[u]) / 2; } int main() { // freopen("inp", "r", stdin); scanf("%d %d", &N, &K); for(int i = 1; i <= N; i++) { scanf("%d", &H[i].val); H[i].id = i; par[i] = i; sz[i] = 1; } for(int i = 1; i <= K; i++) { scanf("%d", &Q[i].val); Q[i].id = i; } sort(H + 1, H + N + 1); sort(Q + 1, Q + K + 1); int p = 1; H[N + 1].val = 1e9; Q[K + 1].val = 1e9; while(Q[p].val < H[1].val) { ans[Q[p].id] = res; p++; } for(int i = 1; i <= N; i++) { int now = H[i].id; res += sz[now]; if(done[findpar(now - 1)]) { merge(now - 1, now); } if(done[findpar(now + 1)]) { merge(now, now + 1); } done[now] = 1; while(Q[p].val < H[i + 1].val) { ans[Q[p].id] = res; p++; } } for(int i = 1; i <= K; i++) { printf("%lld\n", ans[i]); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 6 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 2296 KB | Output is correct |
2 | Correct | 34 ms | 2304 KB | Output is correct |
3 | Correct | 32 ms | 2176 KB | Output is correct |
4 | Correct | 34 ms | 2160 KB | Output is correct |
5 | Correct | 31 ms | 2176 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 4600 KB | Output is correct |
2 | Correct | 62 ms | 4728 KB | Output is correct |
3 | Correct | 60 ms | 4696 KB | Output is correct |
4 | Correct | 58 ms | 4728 KB | Output is correct |
5 | Correct | 58 ms | 4600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 57 ms | 4600 KB | Output is correct |
2 | Correct | 72 ms | 4600 KB | Output is correct |
3 | Correct | 66 ms | 4728 KB | Output is correct |
4 | Correct | 60 ms | 4728 KB | Output is correct |
5 | Correct | 61 ms | 4836 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 38 ms | 2296 KB | Output is correct |
12 | Correct | 34 ms | 2304 KB | Output is correct |
13 | Correct | 32 ms | 2176 KB | Output is correct |
14 | Correct | 34 ms | 2160 KB | Output is correct |
15 | Correct | 31 ms | 2176 KB | Output is correct |
16 | Correct | 31 ms | 2176 KB | Output is correct |
17 | Correct | 33 ms | 2336 KB | Output is correct |
18 | Correct | 33 ms | 2304 KB | Output is correct |
19 | Correct | 31 ms | 2176 KB | Output is correct |
20 | Correct | 33 ms | 2296 KB | Output is correct |
21 | Correct | 31 ms | 2176 KB | Output is correct |
22 | Correct | 31 ms | 2176 KB | Output is correct |
23 | Correct | 35 ms | 2304 KB | Output is correct |
24 | Correct | 31 ms | 2176 KB | Output is correct |
25 | Correct | 33 ms | 2296 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 6 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 38 ms | 2296 KB | Output is correct |
27 | Correct | 34 ms | 2304 KB | Output is correct |
28 | Correct | 32 ms | 2176 KB | Output is correct |
29 | Correct | 34 ms | 2160 KB | Output is correct |
30 | Correct | 31 ms | 2176 KB | Output is correct |
31 | Correct | 56 ms | 4600 KB | Output is correct |
32 | Correct | 62 ms | 4728 KB | Output is correct |
33 | Correct | 60 ms | 4696 KB | Output is correct |
34 | Correct | 58 ms | 4728 KB | Output is correct |
35 | Correct | 58 ms | 4600 KB | Output is correct |
36 | Correct | 57 ms | 4600 KB | Output is correct |
37 | Correct | 72 ms | 4600 KB | Output is correct |
38 | Correct | 66 ms | 4728 KB | Output is correct |
39 | Correct | 60 ms | 4728 KB | Output is correct |
40 | Correct | 61 ms | 4836 KB | Output is correct |
41 | Correct | 31 ms | 2176 KB | Output is correct |
42 | Correct | 33 ms | 2336 KB | Output is correct |
43 | Correct | 33 ms | 2304 KB | Output is correct |
44 | Correct | 31 ms | 2176 KB | Output is correct |
45 | Correct | 33 ms | 2296 KB | Output is correct |
46 | Correct | 31 ms | 2176 KB | Output is correct |
47 | Correct | 31 ms | 2176 KB | Output is correct |
48 | Correct | 35 ms | 2304 KB | Output is correct |
49 | Correct | 31 ms | 2176 KB | Output is correct |
50 | Correct | 33 ms | 2296 KB | Output is correct |
51 | Correct | 69 ms | 4600 KB | Output is correct |
52 | Correct | 69 ms | 4344 KB | Output is correct |
53 | Correct | 72 ms | 4600 KB | Output is correct |
54 | Correct | 70 ms | 4472 KB | Output is correct |
55 | Correct | 69 ms | 4600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 6 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 38 ms | 2296 KB | Output is correct |
27 | Correct | 34 ms | 2304 KB | Output is correct |
28 | Correct | 32 ms | 2176 KB | Output is correct |
29 | Correct | 34 ms | 2160 KB | Output is correct |
30 | Correct | 31 ms | 2176 KB | Output is correct |
31 | Correct | 56 ms | 4600 KB | Output is correct |
32 | Correct | 62 ms | 4728 KB | Output is correct |
33 | Correct | 60 ms | 4696 KB | Output is correct |
34 | Correct | 58 ms | 4728 KB | Output is correct |
35 | Correct | 58 ms | 4600 KB | Output is correct |
36 | Correct | 57 ms | 4600 KB | Output is correct |
37 | Correct | 72 ms | 4600 KB | Output is correct |
38 | Correct | 66 ms | 4728 KB | Output is correct |
39 | Correct | 60 ms | 4728 KB | Output is correct |
40 | Correct | 61 ms | 4836 KB | Output is correct |
41 | Correct | 31 ms | 2176 KB | Output is correct |
42 | Correct | 33 ms | 2336 KB | Output is correct |
43 | Correct | 33 ms | 2304 KB | Output is correct |
44 | Correct | 31 ms | 2176 KB | Output is correct |
45 | Correct | 33 ms | 2296 KB | Output is correct |
46 | Correct | 31 ms | 2176 KB | Output is correct |
47 | Correct | 31 ms | 2176 KB | Output is correct |
48 | Correct | 35 ms | 2304 KB | Output is correct |
49 | Correct | 31 ms | 2176 KB | Output is correct |
50 | Correct | 33 ms | 2296 KB | Output is correct |
51 | Correct | 69 ms | 4600 KB | Output is correct |
52 | Correct | 69 ms | 4344 KB | Output is correct |
53 | Correct | 72 ms | 4600 KB | Output is correct |
54 | Correct | 70 ms | 4472 KB | Output is correct |
55 | Correct | 69 ms | 4600 KB | Output is correct |
56 | Correct | 766 ms | 41980 KB | Output is correct |
57 | Correct | 752 ms | 54136 KB | Output is correct |
58 | Correct | 719 ms | 51580 KB | Output is correct |
59 | Correct | 747 ms | 52908 KB | Output is correct |
60 | Correct | 770 ms | 55196 KB | Output is correct |