Submission #831771

# Submission time Handle Problem Language Result Execution time Memory
831771 2023-08-20T14:15:50 Z nnin Pilot (NOI19_pilot) C++14
100 / 100
439 ms 53092 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
using namespace std;

int n, q;
ll ans[1000002];
pii y[1000002], h[1000002];

ll ctFlights(int mount) {
    return (ll)mount*(mount+1)/2;
}

int dsu[1000002], sz[1000002];
bool over[1000002];
int par(int x) {
    if(dsu[x]==0) return x;
    else return dsu[x] = par(dsu[x]);
}

ll curct;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>q;
    for(int i=1;i<=n;i++) {
        cin>>h[i].f;
        h[i].s = i;
    }
    sort(h+1, h+n+1);
    for(int i=1;i<=q;i++) {
        cin>>y[i].f;
        y[i].s = i;
    }
    sort(y+1, y+q+1);
    int hi = 1;
    for(int yi=1;yi<=q;yi++) {
        while(hi<=n && h[hi].f<=y[yi].f) {
            over[h[hi].s] = 1;
            sz[h[hi].s] = 1;
            if(h[hi].s+1<=n && over[h[hi].s+1]) {
                int p = par(h[hi].s+1);
                curct -= ctFlights(sz[p]);
                dsu[p] = h[hi].s;
                sz[h[hi].s] += sz[p];
            }
            if(h[hi].s-1>=1 && over[h[hi].s-1]) {
                int p = par(h[hi].s-1);
                curct -= ctFlights(sz[p]);
                dsu[h[hi].s] = p;
                sz[p] += sz[h[hi].s];
            }
            curct += ctFlights(sz[par(h[hi].s)]);
            hi++;
        }
        ans[y[yi].s] = curct;
    }
    for(int i=1;i<=q;i++) {
        cout<<ans[i]<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1860 KB Output is correct
2 Correct 16 ms 2644 KB Output is correct
3 Correct 14 ms 2388 KB Output is correct
4 Correct 14 ms 2464 KB Output is correct
5 Correct 15 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 4308 KB Output is correct
2 Correct 27 ms 5452 KB Output is correct
3 Correct 27 ms 5448 KB Output is correct
4 Correct 28 ms 5484 KB Output is correct
5 Correct 27 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4292 KB Output is correct
2 Correct 27 ms 5476 KB Output is correct
3 Correct 29 ms 5580 KB Output is correct
4 Correct 29 ms 5544 KB Output is correct
5 Correct 29 ms 5708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 19 ms 1860 KB Output is correct
12 Correct 16 ms 2644 KB Output is correct
13 Correct 14 ms 2388 KB Output is correct
14 Correct 14 ms 2464 KB Output is correct
15 Correct 15 ms 2496 KB Output is correct
16 Correct 14 ms 2372 KB Output is correct
17 Correct 14 ms 2652 KB Output is correct
18 Correct 14 ms 2644 KB Output is correct
19 Correct 17 ms 2380 KB Output is correct
20 Correct 17 ms 2592 KB Output is correct
21 Correct 15 ms 2296 KB Output is correct
22 Correct 14 ms 2452 KB Output is correct
23 Correct 14 ms 2516 KB Output is correct
24 Correct 13 ms 2396 KB Output is correct
25 Correct 14 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 19 ms 1860 KB Output is correct
27 Correct 16 ms 2644 KB Output is correct
28 Correct 14 ms 2388 KB Output is correct
29 Correct 14 ms 2464 KB Output is correct
30 Correct 15 ms 2496 KB Output is correct
31 Correct 26 ms 4308 KB Output is correct
32 Correct 27 ms 5452 KB Output is correct
33 Correct 27 ms 5448 KB Output is correct
34 Correct 28 ms 5484 KB Output is correct
35 Correct 27 ms 5468 KB Output is correct
36 Correct 31 ms 4292 KB Output is correct
37 Correct 27 ms 5476 KB Output is correct
38 Correct 29 ms 5580 KB Output is correct
39 Correct 29 ms 5544 KB Output is correct
40 Correct 29 ms 5708 KB Output is correct
41 Correct 14 ms 2372 KB Output is correct
42 Correct 14 ms 2652 KB Output is correct
43 Correct 14 ms 2644 KB Output is correct
44 Correct 17 ms 2380 KB Output is correct
45 Correct 17 ms 2592 KB Output is correct
46 Correct 15 ms 2296 KB Output is correct
47 Correct 14 ms 2452 KB Output is correct
48 Correct 14 ms 2516 KB Output is correct
49 Correct 13 ms 2396 KB Output is correct
50 Correct 14 ms 2500 KB Output is correct
51 Correct 36 ms 5444 KB Output is correct
52 Correct 36 ms 5272 KB Output is correct
53 Correct 35 ms 5324 KB Output is correct
54 Correct 40 ms 5324 KB Output is correct
55 Correct 35 ms 5280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 19 ms 1860 KB Output is correct
27 Correct 16 ms 2644 KB Output is correct
28 Correct 14 ms 2388 KB Output is correct
29 Correct 14 ms 2464 KB Output is correct
30 Correct 15 ms 2496 KB Output is correct
31 Correct 26 ms 4308 KB Output is correct
32 Correct 27 ms 5452 KB Output is correct
33 Correct 27 ms 5448 KB Output is correct
34 Correct 28 ms 5484 KB Output is correct
35 Correct 27 ms 5468 KB Output is correct
36 Correct 31 ms 4292 KB Output is correct
37 Correct 27 ms 5476 KB Output is correct
38 Correct 29 ms 5580 KB Output is correct
39 Correct 29 ms 5544 KB Output is correct
40 Correct 29 ms 5708 KB Output is correct
41 Correct 14 ms 2372 KB Output is correct
42 Correct 14 ms 2652 KB Output is correct
43 Correct 14 ms 2644 KB Output is correct
44 Correct 17 ms 2380 KB Output is correct
45 Correct 17 ms 2592 KB Output is correct
46 Correct 15 ms 2296 KB Output is correct
47 Correct 14 ms 2452 KB Output is correct
48 Correct 14 ms 2516 KB Output is correct
49 Correct 13 ms 2396 KB Output is correct
50 Correct 14 ms 2500 KB Output is correct
51 Correct 36 ms 5444 KB Output is correct
52 Correct 36 ms 5272 KB Output is correct
53 Correct 35 ms 5324 KB Output is correct
54 Correct 40 ms 5324 KB Output is correct
55 Correct 35 ms 5280 KB Output is correct
56 Correct 410 ms 51968 KB Output is correct
57 Correct 439 ms 51292 KB Output is correct
58 Correct 381 ms 48736 KB Output is correct
59 Correct 395 ms 49796 KB Output is correct
60 Correct 417 ms 53092 KB Output is correct