Submission #552563

# Submission time Handle Problem Language Result Execution time Memory
552563 2022-04-23T10:07:14 Z RaresFelix Pilot (NOI19_pilot) C++17
40 / 100
47 ms 12940 KB
#include <bits/stdc++.h>
#define MN 1000071

using namespace std;
int n, q, A[MN], On[MN], 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 -= S[v] * (S[v] + 1) / 2;
    rez -= S[u] * (S[u] + 1) / 2;
    S[u] += S[v];
    rez += 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<int> 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 it : R) cout << it << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 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 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 4 ms 8144 KB Output is correct
13 Correct 4 ms 8144 KB Output is correct
14 Correct 5 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 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 4 ms 8144 KB Output is correct
13 Correct 4 ms 8144 KB Output is correct
14 Correct 5 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 5 ms 8148 KB Output is correct
18 Correct 6 ms 8148 KB Output is correct
19 Correct 5 ms 8144 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 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 4 ms 8144 KB Output is correct
13 Correct 4 ms 8144 KB Output is correct
14 Correct 5 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 5 ms 8148 KB Output is correct
18 Correct 6 ms 8148 KB Output is correct
19 Correct 5 ms 8144 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
21 Correct 5 ms 8156 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 6 ms 8156 KB Output is correct
24 Correct 5 ms 8148 KB Output is correct
25 Correct 4 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 10312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 12668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 12940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Incorrect 25 ms 10312 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 4 ms 8144 KB Output is correct
13 Correct 4 ms 8144 KB Output is correct
14 Correct 5 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 5 ms 8148 KB Output is correct
18 Correct 6 ms 8148 KB Output is correct
19 Correct 5 ms 8144 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
21 Correct 5 ms 8156 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 6 ms 8156 KB Output is correct
24 Correct 5 ms 8148 KB Output is correct
25 Correct 4 ms 8156 KB Output is correct
26 Incorrect 25 ms 10312 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 5 ms 8096 KB Output is correct
4 Correct 4 ms 8152 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 8144 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 4 ms 8144 KB Output is correct
13 Correct 4 ms 8144 KB Output is correct
14 Correct 5 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 5 ms 8148 KB Output is correct
18 Correct 6 ms 8148 KB Output is correct
19 Correct 5 ms 8144 KB Output is correct
20 Correct 4 ms 8148 KB Output is correct
21 Correct 5 ms 8156 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 6 ms 8156 KB Output is correct
24 Correct 5 ms 8148 KB Output is correct
25 Correct 4 ms 8156 KB Output is correct
26 Incorrect 25 ms 10312 KB Output isn't correct
27 Halted 0 ms 0 KB -