답안 #318570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318570 2020-11-02T10:51:30 Z ryangohca Pilot (NOI19_pilot) C++17
100 / 100
709 ms 61364 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
vector<pii> heights;
int g[1000005], sz[1000005], ans[1000005];
bool vis[1000005];
int curr = 0;
int find_set(int n){
    if (g[n] == n) return n;
    else return (g[n] = find_set(g[n]));
}
bool is_same_set(int a, int b){
    return find_set(a) == find_set(b);
}
void merge_set(int a, int b){
    int pa = find_set(a), pb = find_set(b);
    curr -= sz[pa] * (sz[pa] + 1) / 2;
    curr -= sz[pb] * (sz[pb] + 1) / 2;
    sz[pb] += sz[pa];
    g[pa] = pb;
    curr += sz[pb] * (sz[pb] + 1) / 2;
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for (int i = 0; i < 1000005; i++){
        g[i] = i;
        sz[i] = 1;
        ans[i] = -1;
    }
    int n, q; cin >> n >> q;
    for (int i = 0; i < n; i++){
        int h; cin >> h;
        heights.push_back({h, i});
    }
    sort(heights.begin(), heights.end());
    int prevh = 1;
    for (int i = 0; i < n; i++){
        auto [h, idx] = heights[i];
        for (int j = prevh; j < h; j++) ans[j] = curr;
        vis[idx] = 1;
        prevh = h;
        curr++;
        if (idx != 0 && vis[idx - 1]) merge_set(idx, idx - 1);
        if (idx != n - 1 && vis[idx + 1]) merge_set(idx, idx + 1);
        ans[h] = curr;
    }
    for (int i = 0; i < q; i++){
        int qi; cin >> qi; cout << ((ans[qi] == -1) ? curr: ans[qi]) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 15 ms 23788 KB Output is correct
14 Correct 15 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 15 ms 23788 KB Output is correct
14 Correct 15 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 14 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 15 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 15 ms 23788 KB Output is correct
14 Correct 15 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 14 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 15 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
21 Correct 15 ms 23916 KB Output is correct
22 Correct 16 ms 23916 KB Output is correct
23 Correct 15 ms 23916 KB Output is correct
24 Correct 16 ms 23916 KB Output is correct
25 Correct 14 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 26088 KB Output is correct
2 Correct 40 ms 26088 KB Output is correct
3 Correct 39 ms 26088 KB Output is correct
4 Correct 37 ms 26088 KB Output is correct
5 Correct 38 ms 26088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 26456 KB Output is correct
2 Correct 55 ms 26584 KB Output is correct
3 Correct 54 ms 26456 KB Output is correct
4 Correct 54 ms 26584 KB Output is correct
5 Correct 54 ms 26456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 26584 KB Output is correct
2 Correct 59 ms 26584 KB Output is correct
3 Correct 60 ms 26480 KB Output is correct
4 Correct 58 ms 26588 KB Output is correct
5 Correct 61 ms 26640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 39 ms 26088 KB Output is correct
12 Correct 40 ms 26088 KB Output is correct
13 Correct 39 ms 26088 KB Output is correct
14 Correct 37 ms 26088 KB Output is correct
15 Correct 38 ms 26088 KB Output is correct
16 Correct 37 ms 26088 KB Output is correct
17 Correct 40 ms 26088 KB Output is correct
18 Correct 40 ms 26088 KB Output is correct
19 Correct 37 ms 26088 KB Output is correct
20 Correct 40 ms 25960 KB Output is correct
21 Correct 38 ms 26080 KB Output is correct
22 Correct 39 ms 26088 KB Output is correct
23 Correct 40 ms 26088 KB Output is correct
24 Correct 38 ms 26088 KB Output is correct
25 Correct 39 ms 26088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 15 ms 23788 KB Output is correct
14 Correct 15 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 14 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 15 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
21 Correct 15 ms 23916 KB Output is correct
22 Correct 16 ms 23916 KB Output is correct
23 Correct 15 ms 23916 KB Output is correct
24 Correct 16 ms 23916 KB Output is correct
25 Correct 14 ms 23916 KB Output is correct
26 Correct 39 ms 26088 KB Output is correct
27 Correct 40 ms 26088 KB Output is correct
28 Correct 39 ms 26088 KB Output is correct
29 Correct 37 ms 26088 KB Output is correct
30 Correct 38 ms 26088 KB Output is correct
31 Correct 53 ms 26456 KB Output is correct
32 Correct 55 ms 26584 KB Output is correct
33 Correct 54 ms 26456 KB Output is correct
34 Correct 54 ms 26584 KB Output is correct
35 Correct 54 ms 26456 KB Output is correct
36 Correct 60 ms 26584 KB Output is correct
37 Correct 59 ms 26584 KB Output is correct
38 Correct 60 ms 26480 KB Output is correct
39 Correct 58 ms 26588 KB Output is correct
40 Correct 61 ms 26640 KB Output is correct
41 Correct 37 ms 26088 KB Output is correct
42 Correct 40 ms 26088 KB Output is correct
43 Correct 40 ms 26088 KB Output is correct
44 Correct 37 ms 26088 KB Output is correct
45 Correct 40 ms 25960 KB Output is correct
46 Correct 38 ms 26080 KB Output is correct
47 Correct 39 ms 26088 KB Output is correct
48 Correct 40 ms 26088 KB Output is correct
49 Correct 38 ms 26088 KB Output is correct
50 Correct 39 ms 26088 KB Output is correct
51 Correct 66 ms 26372 KB Output is correct
52 Correct 69 ms 26200 KB Output is correct
53 Correct 65 ms 26456 KB Output is correct
54 Correct 69 ms 26200 KB Output is correct
55 Correct 68 ms 26452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23836 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 16 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 15 ms 23788 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 15 ms 23788 KB Output is correct
14 Correct 15 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 14 ms 23788 KB Output is correct
17 Correct 16 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 15 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
21 Correct 15 ms 23916 KB Output is correct
22 Correct 16 ms 23916 KB Output is correct
23 Correct 15 ms 23916 KB Output is correct
24 Correct 16 ms 23916 KB Output is correct
25 Correct 14 ms 23916 KB Output is correct
26 Correct 39 ms 26088 KB Output is correct
27 Correct 40 ms 26088 KB Output is correct
28 Correct 39 ms 26088 KB Output is correct
29 Correct 37 ms 26088 KB Output is correct
30 Correct 38 ms 26088 KB Output is correct
31 Correct 53 ms 26456 KB Output is correct
32 Correct 55 ms 26584 KB Output is correct
33 Correct 54 ms 26456 KB Output is correct
34 Correct 54 ms 26584 KB Output is correct
35 Correct 54 ms 26456 KB Output is correct
36 Correct 60 ms 26584 KB Output is correct
37 Correct 59 ms 26584 KB Output is correct
38 Correct 60 ms 26480 KB Output is correct
39 Correct 58 ms 26588 KB Output is correct
40 Correct 61 ms 26640 KB Output is correct
41 Correct 37 ms 26088 KB Output is correct
42 Correct 40 ms 26088 KB Output is correct
43 Correct 40 ms 26088 KB Output is correct
44 Correct 37 ms 26088 KB Output is correct
45 Correct 40 ms 25960 KB Output is correct
46 Correct 38 ms 26080 KB Output is correct
47 Correct 39 ms 26088 KB Output is correct
48 Correct 40 ms 26088 KB Output is correct
49 Correct 38 ms 26088 KB Output is correct
50 Correct 39 ms 26088 KB Output is correct
51 Correct 66 ms 26372 KB Output is correct
52 Correct 69 ms 26200 KB Output is correct
53 Correct 65 ms 26456 KB Output is correct
54 Correct 69 ms 26200 KB Output is correct
55 Correct 68 ms 26452 KB Output is correct
56 Correct 660 ms 52492 KB Output is correct
57 Correct 652 ms 60464 KB Output is correct
58 Correct 619 ms 58288 KB Output is correct
59 Correct 637 ms 59308 KB Output is correct
60 Correct 709 ms 61364 KB Output is correct