답안 #321180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321180 2020-11-11T11:47:19 Z saarang123 Pilot (NOI19_pilot) C++14
100 / 100
723 ms 65508 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define int long long

const int N = 1000 * 1000 + 3;
int par[N], sz[N];
int ans = 0;
bool u[N];

int cnt(int v) { return (v * (v + 1)) / 2; }

void init(int n) {
    for(int i = 0; i <= n + 1; i++) par[i] = i, sz[i] = 1;
}

int fin(int v) { return par[v] == v ? v : par[v] = fin(par[v]); }

void join(int a, int b) {
    if(!u[a] || !u[b]) return;
    a = fin(a); b = fin(b);
    //if(a == b) return;
    ans -= cnt(sz[a]);
    ans -= cnt(sz[b]);
    if(sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
    ans += cnt(sz[a]);
}

void unite(int v) {
    u[v] = 1;
    ans += cnt(sz[v]);
    join(v, v + 1);
    join(v, v - 1);
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n, q;
    cin >> n >> q;
    init(n);
    vector<array<int, 2>> a(n), h(q);
    for(int i = 0; i < n; i++) cin >> a[i][0], a[i][1] = i + 1;
    for(int i = 0; i < q; i++) cin >> h[i][0], h[i][1] = i;
    sort(h.begin(), h.end());
    sort(a.begin(), a.end());
    vector<int> id(q);
    int j = 0;
    for(int i = 0; i < q; i++) {
        while(j < n && a[j][0] <= h[i][0]) {
            unite(a[j][1]);
            j++;
        }
        id[h[i][1]] = ans;
    }
    for(int i = 0; i < q; i++) cout << id[i] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 4076 KB Output is correct
2 Correct 27 ms 4196 KB Output is correct
3 Correct 25 ms 3940 KB Output is correct
4 Correct 24 ms 3948 KB Output is correct
5 Correct 25 ms 3948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 7652 KB Output is correct
2 Correct 49 ms 7780 KB Output is correct
3 Correct 48 ms 7652 KB Output is correct
4 Correct 48 ms 7904 KB Output is correct
5 Correct 51 ms 7652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 7780 KB Output is correct
2 Correct 54 ms 7836 KB Output is correct
3 Correct 49 ms 7908 KB Output is correct
4 Correct 48 ms 7908 KB Output is correct
5 Correct 50 ms 8036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 26 ms 4076 KB Output is correct
12 Correct 27 ms 4196 KB Output is correct
13 Correct 25 ms 3940 KB Output is correct
14 Correct 24 ms 3948 KB Output is correct
15 Correct 25 ms 3948 KB Output is correct
16 Correct 29 ms 3940 KB Output is correct
17 Correct 24 ms 4156 KB Output is correct
18 Correct 23 ms 4204 KB Output is correct
19 Correct 21 ms 3820 KB Output is correct
20 Correct 23 ms 4076 KB Output is correct
21 Correct 26 ms 3820 KB Output is correct
22 Correct 22 ms 3948 KB Output is correct
23 Correct 24 ms 4192 KB Output is correct
24 Correct 21 ms 3948 KB Output is correct
25 Correct 23 ms 4076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 26 ms 4076 KB Output is correct
27 Correct 27 ms 4196 KB Output is correct
28 Correct 25 ms 3940 KB Output is correct
29 Correct 24 ms 3948 KB Output is correct
30 Correct 25 ms 3948 KB Output is correct
31 Correct 49 ms 7652 KB Output is correct
32 Correct 49 ms 7780 KB Output is correct
33 Correct 48 ms 7652 KB Output is correct
34 Correct 48 ms 7904 KB Output is correct
35 Correct 51 ms 7652 KB Output is correct
36 Correct 48 ms 7780 KB Output is correct
37 Correct 54 ms 7836 KB Output is correct
38 Correct 49 ms 7908 KB Output is correct
39 Correct 48 ms 7908 KB Output is correct
40 Correct 50 ms 8036 KB Output is correct
41 Correct 29 ms 3940 KB Output is correct
42 Correct 24 ms 4156 KB Output is correct
43 Correct 23 ms 4204 KB Output is correct
44 Correct 21 ms 3820 KB Output is correct
45 Correct 23 ms 4076 KB Output is correct
46 Correct 26 ms 3820 KB Output is correct
47 Correct 22 ms 3948 KB Output is correct
48 Correct 24 ms 4192 KB Output is correct
49 Correct 21 ms 3948 KB Output is correct
50 Correct 23 ms 4076 KB Output is correct
51 Correct 62 ms 7780 KB Output is correct
52 Correct 59 ms 7652 KB Output is correct
53 Correct 58 ms 7780 KB Output is correct
54 Correct 57 ms 7528 KB Output is correct
55 Correct 58 ms 7652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 26 ms 4076 KB Output is correct
27 Correct 27 ms 4196 KB Output is correct
28 Correct 25 ms 3940 KB Output is correct
29 Correct 24 ms 3948 KB Output is correct
30 Correct 25 ms 3948 KB Output is correct
31 Correct 49 ms 7652 KB Output is correct
32 Correct 49 ms 7780 KB Output is correct
33 Correct 48 ms 7652 KB Output is correct
34 Correct 48 ms 7904 KB Output is correct
35 Correct 51 ms 7652 KB Output is correct
36 Correct 48 ms 7780 KB Output is correct
37 Correct 54 ms 7836 KB Output is correct
38 Correct 49 ms 7908 KB Output is correct
39 Correct 48 ms 7908 KB Output is correct
40 Correct 50 ms 8036 KB Output is correct
41 Correct 29 ms 3940 KB Output is correct
42 Correct 24 ms 4156 KB Output is correct
43 Correct 23 ms 4204 KB Output is correct
44 Correct 21 ms 3820 KB Output is correct
45 Correct 23 ms 4076 KB Output is correct
46 Correct 26 ms 3820 KB Output is correct
47 Correct 22 ms 3948 KB Output is correct
48 Correct 24 ms 4192 KB Output is correct
49 Correct 21 ms 3948 KB Output is correct
50 Correct 23 ms 4076 KB Output is correct
51 Correct 62 ms 7780 KB Output is correct
52 Correct 59 ms 7652 KB Output is correct
53 Correct 58 ms 7780 KB Output is correct
54 Correct 57 ms 7528 KB Output is correct
55 Correct 58 ms 7652 KB Output is correct
56 Correct 709 ms 63972 KB Output is correct
57 Correct 712 ms 63592 KB Output is correct
58 Correct 664 ms 60244 KB Output is correct
59 Correct 678 ms 61668 KB Output is correct
60 Correct 723 ms 65508 KB Output is correct