Submission #552565

# Submission time Handle Problem Language Result Execution time Memory
552565 2022-04-23T10:10:39 Z RaresFelix Pilot (NOI19_pilot) C++17
100 / 100
590 ms 60252 KB
#include <bits/stdc++.h>
#define MN 1000071

using namespace std;
int n, q, A[MN], On[MN];
using ll = long long;
ll rez;
vector<pair<int, int> > Ord;

int P[MN], S[MN];

void init() {
    for(int i = 0; i < MN; ++i)
        S[i] = 1, P[i] = i;
}

int repr(int u) {
    return P[u] == u ? u : (P[u] = repr(P[u]));
}

void uni(int u, int v) {
    u = repr(u), v = repr(v);
    if(u == v) return;
    if(S[u] < S[v]) swap(u, v);
    rez -= 1ll * S[v] * (S[v] + 1) / 2;
    rez -= 1ll * S[u] * (S[u] + 1) / 2;
    S[u] += S[v];
    rez += 1ll * S[u] * (S[u] + 1) / 2;
    P[v] = u;
}

void activ(int p) {
    On[p] = 1, ++rez;
    if(On[p + 1]) uni(p, p + 1);
    if(On[p - 1]) uni(p, p - 1);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    init();
    for(int i = 1; i <= n; ++i) {
        cin >> A[i];
        Ord.push_back({A[i], i});
    }
    sort(Ord.begin(), Ord.end());
    vector<pair<int, int> > Q;
    for(int i = 1, a; i <= q; ++i) {
        cin >> a;
        Q.push_back({a, i-1});
    }
    sort(Q.begin(), Q.end());
    vector<ll> R(q);
    auto it = Q.begin();
    for(auto [a, b] : Ord) {
        while(it != Q.end() && it->first < a)
            R[it->second] = rez, ++it;
        activ(b);
    }
    while(it != Q.end()) R[it->second] = rez, ++it;
    for(auto i : R) cout << i << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8140 KB Output is correct
13 Correct 4 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8140 KB Output is correct
13 Correct 4 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8140 KB Output is correct
13 Correct 4 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 4 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 5 ms 8148 KB Output is correct
25 Correct 5 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 9696 KB Output is correct
2 Correct 23 ms 10460 KB Output is correct
3 Correct 26 ms 10352 KB Output is correct
4 Correct 23 ms 10212 KB Output is correct
5 Correct 24 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 12164 KB Output is correct
2 Correct 41 ms 13384 KB Output is correct
3 Correct 38 ms 13280 KB Output is correct
4 Correct 40 ms 13384 KB Output is correct
5 Correct 36 ms 13308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 12040 KB Output is correct
2 Correct 42 ms 13384 KB Output is correct
3 Correct 43 ms 13380 KB Output is correct
4 Correct 39 ms 13492 KB Output is correct
5 Correct 42 ms 13552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 23 ms 9696 KB Output is correct
12 Correct 23 ms 10460 KB Output is correct
13 Correct 26 ms 10352 KB Output is correct
14 Correct 23 ms 10212 KB Output is correct
15 Correct 24 ms 10332 KB Output is correct
16 Correct 25 ms 10168 KB Output is correct
17 Correct 24 ms 10452 KB Output is correct
18 Correct 26 ms 10464 KB Output is correct
19 Correct 23 ms 10276 KB Output is correct
20 Correct 23 ms 10460 KB Output is correct
21 Correct 23 ms 10164 KB Output is correct
22 Correct 22 ms 10356 KB Output is correct
23 Correct 27 ms 10340 KB Output is correct
24 Correct 24 ms 10320 KB Output is correct
25 Correct 25 ms 10300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8140 KB Output is correct
13 Correct 4 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 4 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 5 ms 8148 KB Output is correct
25 Correct 5 ms 8148 KB Output is correct
26 Correct 23 ms 9696 KB Output is correct
27 Correct 23 ms 10460 KB Output is correct
28 Correct 26 ms 10352 KB Output is correct
29 Correct 23 ms 10212 KB Output is correct
30 Correct 24 ms 10332 KB Output is correct
31 Correct 38 ms 12164 KB Output is correct
32 Correct 41 ms 13384 KB Output is correct
33 Correct 38 ms 13280 KB Output is correct
34 Correct 40 ms 13384 KB Output is correct
35 Correct 36 ms 13308 KB Output is correct
36 Correct 37 ms 12040 KB Output is correct
37 Correct 42 ms 13384 KB Output is correct
38 Correct 43 ms 13380 KB Output is correct
39 Correct 39 ms 13492 KB Output is correct
40 Correct 42 ms 13552 KB Output is correct
41 Correct 25 ms 10168 KB Output is correct
42 Correct 24 ms 10452 KB Output is correct
43 Correct 26 ms 10464 KB Output is correct
44 Correct 23 ms 10276 KB Output is correct
45 Correct 23 ms 10460 KB Output is correct
46 Correct 23 ms 10164 KB Output is correct
47 Correct 22 ms 10356 KB Output is correct
48 Correct 27 ms 10340 KB Output is correct
49 Correct 24 ms 10320 KB Output is correct
50 Correct 25 ms 10300 KB Output is correct
51 Correct 48 ms 13204 KB Output is correct
52 Correct 49 ms 13236 KB Output is correct
53 Correct 57 ms 13232 KB Output is correct
54 Correct 47 ms 13108 KB Output is correct
55 Correct 48 ms 13256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8060 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8140 KB Output is correct
13 Correct 4 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 4 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 5 ms 8148 KB Output is correct
25 Correct 5 ms 8148 KB Output is correct
26 Correct 23 ms 9696 KB Output is correct
27 Correct 23 ms 10460 KB Output is correct
28 Correct 26 ms 10352 KB Output is correct
29 Correct 23 ms 10212 KB Output is correct
30 Correct 24 ms 10332 KB Output is correct
31 Correct 38 ms 12164 KB Output is correct
32 Correct 41 ms 13384 KB Output is correct
33 Correct 38 ms 13280 KB Output is correct
34 Correct 40 ms 13384 KB Output is correct
35 Correct 36 ms 13308 KB Output is correct
36 Correct 37 ms 12040 KB Output is correct
37 Correct 42 ms 13384 KB Output is correct
38 Correct 43 ms 13380 KB Output is correct
39 Correct 39 ms 13492 KB Output is correct
40 Correct 42 ms 13552 KB Output is correct
41 Correct 25 ms 10168 KB Output is correct
42 Correct 24 ms 10452 KB Output is correct
43 Correct 26 ms 10464 KB Output is correct
44 Correct 23 ms 10276 KB Output is correct
45 Correct 23 ms 10460 KB Output is correct
46 Correct 23 ms 10164 KB Output is correct
47 Correct 22 ms 10356 KB Output is correct
48 Correct 27 ms 10340 KB Output is correct
49 Correct 24 ms 10320 KB Output is correct
50 Correct 25 ms 10300 KB Output is correct
51 Correct 48 ms 13204 KB Output is correct
52 Correct 49 ms 13236 KB Output is correct
53 Correct 57 ms 13232 KB Output is correct
54 Correct 47 ms 13108 KB Output is correct
55 Correct 48 ms 13256 KB Output is correct
56 Correct 537 ms 59096 KB Output is correct
57 Correct 590 ms 58368 KB Output is correct
58 Correct 502 ms 55976 KB Output is correct
59 Correct 511 ms 56832 KB Output is correct
60 Correct 546 ms 60252 KB Output is correct