답안 #318568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318568 2020-11-02T10:50:16 Z ryangohca Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 48812 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() {
    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 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
11 Correct 14 ms 23908 KB Output is correct
12 Correct 16 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 15 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
11 Correct 14 ms 23908 KB Output is correct
12 Correct 16 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 15 ms 24044 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 16 ms 23788 KB Output is correct
19 Correct 16 ms 23784 KB Output is correct
20 Correct 15 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
11 Correct 14 ms 23908 KB Output is correct
12 Correct 16 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 15 ms 24044 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 16 ms 23788 KB Output is correct
19 Correct 16 ms 23784 KB Output is correct
20 Correct 15 ms 23788 KB Output is correct
21 Correct 18 ms 23916 KB Output is correct
22 Correct 18 ms 23916 KB Output is correct
23 Correct 17 ms 23916 KB Output is correct
24 Correct 18 ms 23916 KB Output is correct
25 Correct 18 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 26584 KB Output is correct
2 Correct 64 ms 26592 KB Output is correct
3 Correct 57 ms 26584 KB Output is correct
4 Correct 60 ms 26712 KB Output is correct
5 Correct 60 ms 26524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 299 ms 27728 KB Output is correct
2 Correct 304 ms 27600 KB Output is correct
3 Correct 304 ms 27984 KB Output is correct
4 Correct 301 ms 27728 KB Output is correct
5 Correct 299 ms 27728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 27728 KB Output is correct
2 Correct 308 ms 27728 KB Output is correct
3 Correct 317 ms 27692 KB Output is correct
4 Correct 309 ms 27856 KB Output is correct
5 Correct 323 ms 27868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
11 Correct 60 ms 26584 KB Output is correct
12 Correct 64 ms 26592 KB Output is correct
13 Correct 57 ms 26584 KB Output is correct
14 Correct 60 ms 26712 KB Output is correct
15 Correct 60 ms 26524 KB Output is correct
16 Correct 57 ms 26492 KB Output is correct
17 Correct 62 ms 26584 KB Output is correct
18 Correct 64 ms 26584 KB Output is correct
19 Correct 56 ms 26584 KB Output is correct
20 Correct 63 ms 26584 KB Output is correct
21 Correct 57 ms 26584 KB Output is correct
22 Correct 60 ms 26584 KB Output is correct
23 Correct 60 ms 26588 KB Output is correct
24 Correct 59 ms 26584 KB Output is correct
25 Correct 58 ms 26584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
11 Correct 14 ms 23908 KB Output is correct
12 Correct 16 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 15 ms 24044 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 16 ms 23788 KB Output is correct
19 Correct 16 ms 23784 KB Output is correct
20 Correct 15 ms 23788 KB Output is correct
21 Correct 18 ms 23916 KB Output is correct
22 Correct 18 ms 23916 KB Output is correct
23 Correct 17 ms 23916 KB Output is correct
24 Correct 18 ms 23916 KB Output is correct
25 Correct 18 ms 23916 KB Output is correct
26 Correct 60 ms 26584 KB Output is correct
27 Correct 64 ms 26592 KB Output is correct
28 Correct 57 ms 26584 KB Output is correct
29 Correct 60 ms 26712 KB Output is correct
30 Correct 60 ms 26524 KB Output is correct
31 Correct 299 ms 27728 KB Output is correct
32 Correct 304 ms 27600 KB Output is correct
33 Correct 304 ms 27984 KB Output is correct
34 Correct 301 ms 27728 KB Output is correct
35 Correct 299 ms 27728 KB Output is correct
36 Correct 302 ms 27728 KB Output is correct
37 Correct 308 ms 27728 KB Output is correct
38 Correct 317 ms 27692 KB Output is correct
39 Correct 309 ms 27856 KB Output is correct
40 Correct 323 ms 27868 KB Output is correct
41 Correct 57 ms 26492 KB Output is correct
42 Correct 62 ms 26584 KB Output is correct
43 Correct 64 ms 26584 KB Output is correct
44 Correct 56 ms 26584 KB Output is correct
45 Correct 63 ms 26584 KB Output is correct
46 Correct 57 ms 26584 KB Output is correct
47 Correct 60 ms 26584 KB Output is correct
48 Correct 60 ms 26588 KB Output is correct
49 Correct 59 ms 26584 KB Output is correct
50 Correct 58 ms 26584 KB Output is correct
51 Correct 320 ms 27472 KB Output is correct
52 Correct 325 ms 27600 KB Output is correct
53 Correct 316 ms 27600 KB Output is correct
54 Correct 320 ms 27596 KB Output is correct
55 Correct 307 ms 27728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 19 ms 23788 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 15 ms 23788 KB Output is correct
6 Correct 15 ms 23788 KB Output is correct
7 Correct 16 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 14 ms 23788 KB Output is correct
11 Correct 14 ms 23908 KB Output is correct
12 Correct 16 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 15 ms 24044 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 16 ms 23788 KB Output is correct
19 Correct 16 ms 23784 KB Output is correct
20 Correct 15 ms 23788 KB Output is correct
21 Correct 18 ms 23916 KB Output is correct
22 Correct 18 ms 23916 KB Output is correct
23 Correct 17 ms 23916 KB Output is correct
24 Correct 18 ms 23916 KB Output is correct
25 Correct 18 ms 23916 KB Output is correct
26 Correct 60 ms 26584 KB Output is correct
27 Correct 64 ms 26592 KB Output is correct
28 Correct 57 ms 26584 KB Output is correct
29 Correct 60 ms 26712 KB Output is correct
30 Correct 60 ms 26524 KB Output is correct
31 Correct 299 ms 27728 KB Output is correct
32 Correct 304 ms 27600 KB Output is correct
33 Correct 304 ms 27984 KB Output is correct
34 Correct 301 ms 27728 KB Output is correct
35 Correct 299 ms 27728 KB Output is correct
36 Correct 302 ms 27728 KB Output is correct
37 Correct 308 ms 27728 KB Output is correct
38 Correct 317 ms 27692 KB Output is correct
39 Correct 309 ms 27856 KB Output is correct
40 Correct 323 ms 27868 KB Output is correct
41 Correct 57 ms 26492 KB Output is correct
42 Correct 62 ms 26584 KB Output is correct
43 Correct 64 ms 26584 KB Output is correct
44 Correct 56 ms 26584 KB Output is correct
45 Correct 63 ms 26584 KB Output is correct
46 Correct 57 ms 26584 KB Output is correct
47 Correct 60 ms 26584 KB Output is correct
48 Correct 60 ms 26588 KB Output is correct
49 Correct 59 ms 26584 KB Output is correct
50 Correct 58 ms 26584 KB Output is correct
51 Correct 320 ms 27472 KB Output is correct
52 Correct 325 ms 27600 KB Output is correct
53 Correct 316 ms 27600 KB Output is correct
54 Correct 320 ms 27596 KB Output is correct
55 Correct 307 ms 27728 KB Output is correct
56 Execution timed out 1077 ms 48812 KB Time limit exceeded
57 Halted 0 ms 0 KB -