Submission #516373

# Submission time Handle Problem Language Result Execution time Memory
516373 2022-01-21T08:46:53 Z Jomnoi Pilot (NOI19_pilot) C++17
100 / 100
746 ms 80612 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int N = 1e6 + 10;
const int MAX_H = 1e6;

vector <int> Q[N];
bool visited[N];
int parent[N];
int sz[N];
long long qs[N];

int root(int u) {
    if(u == parent[u]) {
        return u;
    }
    return parent[u] = root(parent[u]);
}

long long cal(int x) {
    return 1ll * x * (x + 1) / 2;
}

int main() {
    int n, q;
    scanf(" %d %d", &n, &q);
    for(int i = 1; i <= n; i++) {
        parent[i] = i;
        sz[i] = 1;
    }

    for(int i = 1; i <= n; i++) {
        int h;
        scanf(" %d", &h);
        Q[h].push_back(i);
    }
    
    for(int h = 1; h <= MAX_H; h++) {
        qs[h] = qs[h - 1];
        for(auto i : Q[h]) {
            visited[i] = true;
            qs[h]++;
            if(visited[i - 1] == true) {
                int u = root(i), v = root(i - 1);
                qs[h] -= cal(sz[u]) + cal(sz[v]);

                if(sz[u] < sz[v]) {
                    swap(u, v);
                }
                sz[u] += sz[v];
                parent[v] = u;
                qs[h] += cal(sz[u]);
            }
            if(visited[i + 1] == true) {
                int u = root(i), v = root(i + 1);
                qs[h] -= cal(sz[u]) + cal(sz[v]);

                if(sz[u] < sz[v]) {
                    swap(u, v);
                }
                sz[u] += sz[v];
                parent[v] = u;
                qs[h] += cal(sz[u]);
            }
        }
    }

    while(q--) {
        int y;
        scanf(" %d", &y);
        printf("%lld\n", qs[y]);
    }
    return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf(" %d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
pilot.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf(" %d", &h);
      |         ~~~~~^~~~~~~~~~~
pilot.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf(" %d", &y);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
11 Correct 17 ms 31564 KB Output is correct
12 Correct 17 ms 31592 KB Output is correct
13 Correct 16 ms 31564 KB Output is correct
14 Correct 16 ms 31612 KB Output is correct
15 Correct 18 ms 31696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
11 Correct 17 ms 31564 KB Output is correct
12 Correct 17 ms 31592 KB Output is correct
13 Correct 16 ms 31564 KB Output is correct
14 Correct 16 ms 31612 KB Output is correct
15 Correct 18 ms 31696 KB Output is correct
16 Correct 17 ms 31564 KB Output is correct
17 Correct 20 ms 31588 KB Output is correct
18 Correct 17 ms 31636 KB Output is correct
19 Correct 18 ms 31504 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
11 Correct 17 ms 31564 KB Output is correct
12 Correct 17 ms 31592 KB Output is correct
13 Correct 16 ms 31564 KB Output is correct
14 Correct 16 ms 31612 KB Output is correct
15 Correct 18 ms 31696 KB Output is correct
16 Correct 17 ms 31564 KB Output is correct
17 Correct 20 ms 31588 KB Output is correct
18 Correct 17 ms 31636 KB Output is correct
19 Correct 18 ms 31504 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
21 Correct 17 ms 31600 KB Output is correct
22 Correct 17 ms 31556 KB Output is correct
23 Correct 17 ms 31564 KB Output is correct
24 Correct 19 ms 31684 KB Output is correct
25 Correct 17 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 34828 KB Output is correct
2 Correct 58 ms 36032 KB Output is correct
3 Correct 43 ms 34772 KB Output is correct
4 Correct 52 ms 35700 KB Output is correct
5 Correct 39 ms 34716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 37416 KB Output is correct
2 Correct 60 ms 37404 KB Output is correct
3 Correct 56 ms 37316 KB Output is correct
4 Correct 57 ms 37584 KB Output is correct
5 Correct 56 ms 37316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 37572 KB Output is correct
2 Correct 65 ms 37512 KB Output is correct
3 Correct 64 ms 37432 KB Output is correct
4 Correct 69 ms 37828 KB Output is correct
5 Correct 67 ms 37648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
11 Correct 42 ms 34828 KB Output is correct
12 Correct 58 ms 36032 KB Output is correct
13 Correct 43 ms 34772 KB Output is correct
14 Correct 52 ms 35700 KB Output is correct
15 Correct 39 ms 34716 KB Output is correct
16 Correct 39 ms 34780 KB Output is correct
17 Correct 55 ms 36036 KB Output is correct
18 Correct 56 ms 36036 KB Output is correct
19 Correct 41 ms 34652 KB Output is correct
20 Correct 54 ms 35980 KB Output is correct
21 Correct 41 ms 34684 KB Output is correct
22 Correct 54 ms 35696 KB Output is correct
23 Correct 41 ms 34996 KB Output is correct
24 Correct 54 ms 35716 KB Output is correct
25 Correct 40 ms 34884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
11 Correct 17 ms 31564 KB Output is correct
12 Correct 17 ms 31592 KB Output is correct
13 Correct 16 ms 31564 KB Output is correct
14 Correct 16 ms 31612 KB Output is correct
15 Correct 18 ms 31696 KB Output is correct
16 Correct 17 ms 31564 KB Output is correct
17 Correct 20 ms 31588 KB Output is correct
18 Correct 17 ms 31636 KB Output is correct
19 Correct 18 ms 31504 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
21 Correct 17 ms 31600 KB Output is correct
22 Correct 17 ms 31556 KB Output is correct
23 Correct 17 ms 31564 KB Output is correct
24 Correct 19 ms 31684 KB Output is correct
25 Correct 17 ms 31596 KB Output is correct
26 Correct 42 ms 34828 KB Output is correct
27 Correct 58 ms 36032 KB Output is correct
28 Correct 43 ms 34772 KB Output is correct
29 Correct 52 ms 35700 KB Output is correct
30 Correct 39 ms 34716 KB Output is correct
31 Correct 58 ms 37416 KB Output is correct
32 Correct 60 ms 37404 KB Output is correct
33 Correct 56 ms 37316 KB Output is correct
34 Correct 57 ms 37584 KB Output is correct
35 Correct 56 ms 37316 KB Output is correct
36 Correct 59 ms 37572 KB Output is correct
37 Correct 65 ms 37512 KB Output is correct
38 Correct 64 ms 37432 KB Output is correct
39 Correct 69 ms 37828 KB Output is correct
40 Correct 67 ms 37648 KB Output is correct
41 Correct 39 ms 34780 KB Output is correct
42 Correct 55 ms 36036 KB Output is correct
43 Correct 56 ms 36036 KB Output is correct
44 Correct 41 ms 34652 KB Output is correct
45 Correct 54 ms 35980 KB Output is correct
46 Correct 41 ms 34684 KB Output is correct
47 Correct 54 ms 35696 KB Output is correct
48 Correct 41 ms 34996 KB Output is correct
49 Correct 54 ms 35716 KB Output is correct
50 Correct 40 ms 34884 KB Output is correct
51 Correct 64 ms 36292 KB Output is correct
52 Correct 96 ms 37092 KB Output is correct
53 Correct 66 ms 36344 KB Output is correct
54 Correct 79 ms 37152 KB Output is correct
55 Correct 66 ms 36292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31556 KB Output is correct
2 Correct 16 ms 31556 KB Output is correct
3 Correct 17 ms 31588 KB Output is correct
4 Correct 17 ms 31524 KB Output is correct
5 Correct 16 ms 31564 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31524 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 18 ms 31608 KB Output is correct
10 Correct 16 ms 31596 KB Output is correct
11 Correct 17 ms 31564 KB Output is correct
12 Correct 17 ms 31592 KB Output is correct
13 Correct 16 ms 31564 KB Output is correct
14 Correct 16 ms 31612 KB Output is correct
15 Correct 18 ms 31696 KB Output is correct
16 Correct 17 ms 31564 KB Output is correct
17 Correct 20 ms 31588 KB Output is correct
18 Correct 17 ms 31636 KB Output is correct
19 Correct 18 ms 31504 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
21 Correct 17 ms 31600 KB Output is correct
22 Correct 17 ms 31556 KB Output is correct
23 Correct 17 ms 31564 KB Output is correct
24 Correct 19 ms 31684 KB Output is correct
25 Correct 17 ms 31596 KB Output is correct
26 Correct 42 ms 34828 KB Output is correct
27 Correct 58 ms 36032 KB Output is correct
28 Correct 43 ms 34772 KB Output is correct
29 Correct 52 ms 35700 KB Output is correct
30 Correct 39 ms 34716 KB Output is correct
31 Correct 58 ms 37416 KB Output is correct
32 Correct 60 ms 37404 KB Output is correct
33 Correct 56 ms 37316 KB Output is correct
34 Correct 57 ms 37584 KB Output is correct
35 Correct 56 ms 37316 KB Output is correct
36 Correct 59 ms 37572 KB Output is correct
37 Correct 65 ms 37512 KB Output is correct
38 Correct 64 ms 37432 KB Output is correct
39 Correct 69 ms 37828 KB Output is correct
40 Correct 67 ms 37648 KB Output is correct
41 Correct 39 ms 34780 KB Output is correct
42 Correct 55 ms 36036 KB Output is correct
43 Correct 56 ms 36036 KB Output is correct
44 Correct 41 ms 34652 KB Output is correct
45 Correct 54 ms 35980 KB Output is correct
46 Correct 41 ms 34684 KB Output is correct
47 Correct 54 ms 35696 KB Output is correct
48 Correct 41 ms 34996 KB Output is correct
49 Correct 54 ms 35716 KB Output is correct
50 Correct 40 ms 34884 KB Output is correct
51 Correct 64 ms 36292 KB Output is correct
52 Correct 96 ms 37092 KB Output is correct
53 Correct 66 ms 36344 KB Output is correct
54 Correct 79 ms 37152 KB Output is correct
55 Correct 66 ms 36292 KB Output is correct
56 Correct 708 ms 79220 KB Output is correct
57 Correct 738 ms 80152 KB Output is correct
58 Correct 677 ms 76640 KB Output is correct
59 Correct 698 ms 78332 KB Output is correct
60 Correct 746 ms 80612 KB Output is correct