Submission #894917

# Submission time Handle Problem Language Result Execution time Memory
894917 2023-12-29T08:19:57 Z votranngocvy Pilot (NOI19_pilot) C++14
100 / 100
447 ms 63556 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
const int N = 1e6 + 5;
pii a[N],b[N];
int par[N],sz[N],ans,res[N];
bool f[N];

void make_set(int v) {
    par[v] = v;
    sz[v] = 1;
}

int find_set(int v) {
    if (v == par[v]) return v;
    int p = find_set(par[v]);
    par[v] = p;
    return p;
}

void union_sets(int a,int b) {
    a = find_set(a),b = find_set(b);
    if (a == b) return;
    ans -= (sz[a] * (sz[a] + 1)) / 2 + (sz[b] * (sz[b] + 1)) / 2;
    if (sz[a] < sz[b]) swap(a,b);
    sz[a] += sz[b];
    par[b] = a;
    ans += (sz[a] * (sz[a] + 1)) / 2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(a + 1,a + n + 1);
    for (int i = 1; i <= q; i++) {
        cin >> b[i].fi;
        b[i].se = i;
    }
    sort(b + 1,b + q + 1);
    int j = 1;
    for (int i = 1; i <= n; i++) make_set(i);
    for (int i = 1; i <= q; i++) {
        while (j <= n && a[j].fi <= b[i].fi) {
            ans++;
            if (a[j].se > 1 && f[a[j].se - 1]) union_sets(a[j].se,a[j].se - 1);
            if (a[j].se < n && f[a[j].se + 1]) union_sets(a[j].se,a[j].se + 1);
            f[a[j].se] = true;
            j++;
        }
        res[b[i].se] = ans;
    }
    for (int i = 1; i <= q; i++) cout << res[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10584 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10584 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 1 ms 10588 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12636 KB Output is correct
2 Correct 19 ms 12756 KB Output is correct
3 Correct 16 ms 12744 KB Output is correct
4 Correct 15 ms 12636 KB Output is correct
5 Correct 15 ms 12756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 15708 KB Output is correct
2 Correct 27 ms 15696 KB Output is correct
3 Correct 32 ms 15836 KB Output is correct
4 Correct 27 ms 15700 KB Output is correct
5 Correct 26 ms 15696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 15708 KB Output is correct
2 Correct 27 ms 15740 KB Output is correct
3 Correct 28 ms 15696 KB Output is correct
4 Correct 33 ms 15696 KB Output is correct
5 Correct 28 ms 15696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 16 ms 12636 KB Output is correct
12 Correct 19 ms 12756 KB Output is correct
13 Correct 16 ms 12744 KB Output is correct
14 Correct 15 ms 12636 KB Output is correct
15 Correct 15 ms 12756 KB Output is correct
16 Correct 14 ms 12760 KB Output is correct
17 Correct 14 ms 12636 KB Output is correct
18 Correct 14 ms 12760 KB Output is correct
19 Correct 13 ms 12640 KB Output is correct
20 Correct 16 ms 12640 KB Output is correct
21 Correct 15 ms 12636 KB Output is correct
22 Correct 14 ms 12640 KB Output is correct
23 Correct 14 ms 12768 KB Output is correct
24 Correct 13 ms 12760 KB Output is correct
25 Correct 15 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10584 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 1 ms 10588 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 16 ms 12636 KB Output is correct
27 Correct 19 ms 12756 KB Output is correct
28 Correct 16 ms 12744 KB Output is correct
29 Correct 15 ms 12636 KB Output is correct
30 Correct 15 ms 12756 KB Output is correct
31 Correct 27 ms 15708 KB Output is correct
32 Correct 27 ms 15696 KB Output is correct
33 Correct 32 ms 15836 KB Output is correct
34 Correct 27 ms 15700 KB Output is correct
35 Correct 26 ms 15696 KB Output is correct
36 Correct 27 ms 15708 KB Output is correct
37 Correct 27 ms 15740 KB Output is correct
38 Correct 28 ms 15696 KB Output is correct
39 Correct 33 ms 15696 KB Output is correct
40 Correct 28 ms 15696 KB Output is correct
41 Correct 14 ms 12760 KB Output is correct
42 Correct 14 ms 12636 KB Output is correct
43 Correct 14 ms 12760 KB Output is correct
44 Correct 13 ms 12640 KB Output is correct
45 Correct 16 ms 12640 KB Output is correct
46 Correct 15 ms 12636 KB Output is correct
47 Correct 14 ms 12640 KB Output is correct
48 Correct 14 ms 12768 KB Output is correct
49 Correct 13 ms 12760 KB Output is correct
50 Correct 15 ms 12636 KB Output is correct
51 Correct 35 ms 15700 KB Output is correct
52 Correct 35 ms 15508 KB Output is correct
53 Correct 35 ms 15696 KB Output is correct
54 Correct 34 ms 15444 KB Output is correct
55 Correct 34 ms 15696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 2 ms 10704 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10584 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 1 ms 10588 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 16 ms 12636 KB Output is correct
27 Correct 19 ms 12756 KB Output is correct
28 Correct 16 ms 12744 KB Output is correct
29 Correct 15 ms 12636 KB Output is correct
30 Correct 15 ms 12756 KB Output is correct
31 Correct 27 ms 15708 KB Output is correct
32 Correct 27 ms 15696 KB Output is correct
33 Correct 32 ms 15836 KB Output is correct
34 Correct 27 ms 15700 KB Output is correct
35 Correct 26 ms 15696 KB Output is correct
36 Correct 27 ms 15708 KB Output is correct
37 Correct 27 ms 15740 KB Output is correct
38 Correct 28 ms 15696 KB Output is correct
39 Correct 33 ms 15696 KB Output is correct
40 Correct 28 ms 15696 KB Output is correct
41 Correct 14 ms 12760 KB Output is correct
42 Correct 14 ms 12636 KB Output is correct
43 Correct 14 ms 12760 KB Output is correct
44 Correct 13 ms 12640 KB Output is correct
45 Correct 16 ms 12640 KB Output is correct
46 Correct 15 ms 12636 KB Output is correct
47 Correct 14 ms 12640 KB Output is correct
48 Correct 14 ms 12768 KB Output is correct
49 Correct 13 ms 12760 KB Output is correct
50 Correct 15 ms 12636 KB Output is correct
51 Correct 35 ms 15700 KB Output is correct
52 Correct 35 ms 15508 KB Output is correct
53 Correct 35 ms 15696 KB Output is correct
54 Correct 34 ms 15444 KB Output is correct
55 Correct 34 ms 15696 KB Output is correct
56 Correct 447 ms 63556 KB Output is correct
57 Correct 411 ms 63056 KB Output is correct
58 Correct 422 ms 62800 KB Output is correct
59 Correct 400 ms 62936 KB Output is correct
60 Correct 428 ms 63284 KB Output is correct