# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943210 | 2024-03-11T09:19:51 Z | Lilypad | Pilot (NOI19_pilot) | C++14 | 451 ms | 60500 KB |
#include<bits/stdc++.h> using namespace std; #define ll int #define pii pair<ll,ll> #define pb push_back #define fi first #define se second const ll N = 1e6+5; ll n,q,tmp; long long ans,ansq[N],sz[N]; ll par[N],a[N]; pii b[N],x[N]; ll root(ll x) { if(par[x] == x) return x; return par[x] = root(par[x]); } void join(ll y, ll z) { ll ry = root(y); ll rz = root(z); if(ry == rz) return; par[ry] = rz; ans -= (sz[rz] + sz[ry]); ans -= (sz[rz]*(sz[rz]-1))/2; ans -= (sz[ry]*(sz[ry]-1))/2; sz[rz] += sz[ry]; ans += (sz[rz]*(sz[rz]-1))/2 + sz[rz]; } int main() { // ios_base::sync_with_stdio(0); // cin.tie(0); scanf("%d %d", &n, &q); for(int i=1; i<=n; i++) { scanf("%d", &a[i]); b[i].fi = a[i]; b[i].se = i; par[i] = i; } sort(b+1,b+n+1); for(int i=1; i<=q; i++) { scanf("%d", &x[i].fi); x[i].se = i; } sort(x+1,x+q+1); ll idx = 1; for(int i=1; i<=q; i++) { while(idx <= n && b[idx].fi <= x[i].fi) { ll var = b[idx].se; sz[var] = 1; ans++; if(var > 1 && sz[var-1] > 0) join(var-1,var); if(var < n && sz[var+1] > 0) join(var+1,var); idx++; } ansq[x[i].se] = ans; } for(int i=1; i<=q; i++) printf("%lld\n", ansq[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 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 | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 10588 KB | Output is correct |
10 | Correct | 1 ms | 10588 KB | Output is correct |
11 | Correct | 1 ms | 10584 KB | Output is correct |
12 | Correct | 1 ms | 10588 KB | Output is correct |
13 | Correct | 2 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 | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 10588 KB | Output is correct |
10 | Correct | 1 ms | 10588 KB | Output is correct |
11 | Correct | 1 ms | 10584 KB | Output is correct |
12 | Correct | 1 ms | 10588 KB | Output is correct |
13 | Correct | 2 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 | 2 ms | 10588 KB | Output is correct |
17 | Correct | 2 ms | 10588 KB | Output is correct |
18 | Correct | 1 ms | 10588 KB | Output is correct |
19 | Correct | 2 ms | 10588 KB | Output is correct |
20 | Correct | 2 ms | 10588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 10588 KB | Output is correct |
10 | Correct | 1 ms | 10588 KB | Output is correct |
11 | Correct | 1 ms | 10584 KB | Output is correct |
12 | Correct | 1 ms | 10588 KB | Output is correct |
13 | Correct | 2 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 | 2 ms | 10588 KB | Output is correct |
17 | Correct | 2 ms | 10588 KB | Output is correct |
18 | Correct | 1 ms | 10588 KB | Output is correct |
19 | Correct | 2 ms | 10588 KB | Output is correct |
20 | Correct | 2 ms | 10588 KB | Output is correct |
21 | Correct | 2 ms | 10588 KB | Output is correct |
22 | Correct | 2 ms | 10588 KB | Output is correct |
23 | Correct | 2 ms | 10588 KB | Output is correct |
24 | Correct | 2 ms | 10676 KB | Output is correct |
25 | Correct | 2 ms | 10584 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 12632 KB | Output is correct |
2 | Correct | 17 ms | 12636 KB | Output is correct |
3 | Correct | 16 ms | 12636 KB | Output is correct |
4 | Correct | 16 ms | 12748 KB | Output is correct |
5 | Correct | 16 ms | 12632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 15708 KB | Output is correct |
2 | Correct | 32 ms | 15964 KB | Output is correct |
3 | Correct | 31 ms | 15980 KB | Output is correct |
4 | Correct | 31 ms | 15964 KB | Output is correct |
5 | Correct | 31 ms | 15940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 15696 KB | Output is correct |
2 | Correct | 32 ms | 15696 KB | Output is correct |
3 | Correct | 32 ms | 15952 KB | Output is correct |
4 | Correct | 31 ms | 15708 KB | Output is correct |
5 | Correct | 33 ms | 15956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 10588 KB | Output is correct |
10 | Correct | 1 ms | 10588 KB | Output is correct |
11 | Correct | 17 ms | 12632 KB | Output is correct |
12 | Correct | 17 ms | 12636 KB | Output is correct |
13 | Correct | 16 ms | 12636 KB | Output is correct |
14 | Correct | 16 ms | 12748 KB | Output is correct |
15 | Correct | 16 ms | 12632 KB | Output is correct |
16 | Correct | 15 ms | 12632 KB | Output is correct |
17 | Correct | 15 ms | 12632 KB | Output is correct |
18 | Correct | 15 ms | 12632 KB | Output is correct |
19 | Correct | 16 ms | 12636 KB | Output is correct |
20 | Correct | 15 ms | 12736 KB | Output is correct |
21 | Correct | 20 ms | 12636 KB | Output is correct |
22 | Correct | 15 ms | 12636 KB | Output is correct |
23 | Correct | 15 ms | 12636 KB | Output is correct |
24 | Correct | 14 ms | 12740 KB | Output is correct |
25 | Correct | 16 ms | 12636 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 10588 KB | Output is correct |
10 | Correct | 1 ms | 10588 KB | Output is correct |
11 | Correct | 1 ms | 10584 KB | Output is correct |
12 | Correct | 1 ms | 10588 KB | Output is correct |
13 | Correct | 2 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 | 2 ms | 10588 KB | Output is correct |
17 | Correct | 2 ms | 10588 KB | Output is correct |
18 | Correct | 1 ms | 10588 KB | Output is correct |
19 | Correct | 2 ms | 10588 KB | Output is correct |
20 | Correct | 2 ms | 10588 KB | Output is correct |
21 | Correct | 2 ms | 10588 KB | Output is correct |
22 | Correct | 2 ms | 10588 KB | Output is correct |
23 | Correct | 2 ms | 10588 KB | Output is correct |
24 | Correct | 2 ms | 10676 KB | Output is correct |
25 | Correct | 2 ms | 10584 KB | Output is correct |
26 | Correct | 17 ms | 12632 KB | Output is correct |
27 | Correct | 17 ms | 12636 KB | Output is correct |
28 | Correct | 16 ms | 12636 KB | Output is correct |
29 | Correct | 16 ms | 12748 KB | Output is correct |
30 | Correct | 16 ms | 12632 KB | Output is correct |
31 | Correct | 30 ms | 15708 KB | Output is correct |
32 | Correct | 32 ms | 15964 KB | Output is correct |
33 | Correct | 31 ms | 15980 KB | Output is correct |
34 | Correct | 31 ms | 15964 KB | Output is correct |
35 | Correct | 31 ms | 15940 KB | Output is correct |
36 | Correct | 39 ms | 15696 KB | Output is correct |
37 | Correct | 32 ms | 15696 KB | Output is correct |
38 | Correct | 32 ms | 15952 KB | Output is correct |
39 | Correct | 31 ms | 15708 KB | Output is correct |
40 | Correct | 33 ms | 15956 KB | Output is correct |
41 | Correct | 15 ms | 12632 KB | Output is correct |
42 | Correct | 15 ms | 12632 KB | Output is correct |
43 | Correct | 15 ms | 12632 KB | Output is correct |
44 | Correct | 16 ms | 12636 KB | Output is correct |
45 | Correct | 15 ms | 12736 KB | Output is correct |
46 | Correct | 20 ms | 12636 KB | Output is correct |
47 | Correct | 15 ms | 12636 KB | Output is correct |
48 | Correct | 15 ms | 12636 KB | Output is correct |
49 | Correct | 14 ms | 12740 KB | Output is correct |
50 | Correct | 16 ms | 12636 KB | Output is correct |
51 | Correct | 40 ms | 15696 KB | Output is correct |
52 | Correct | 39 ms | 15440 KB | Output is correct |
53 | Correct | 38 ms | 15708 KB | Output is correct |
54 | Correct | 38 ms | 15476 KB | Output is correct |
55 | Correct | 40 ms | 15728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10588 KB | Output is correct |
2 | Correct | 1 ms | 10588 KB | Output is correct |
3 | Correct | 1 ms | 10584 KB | Output is correct |
4 | Correct | 1 ms | 10588 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 10588 KB | Output is correct |
7 | Correct | 1 ms | 10588 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 10588 KB | Output is correct |
10 | Correct | 1 ms | 10588 KB | Output is correct |
11 | Correct | 1 ms | 10584 KB | Output is correct |
12 | Correct | 1 ms | 10588 KB | Output is correct |
13 | Correct | 2 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 | 2 ms | 10588 KB | Output is correct |
17 | Correct | 2 ms | 10588 KB | Output is correct |
18 | Correct | 1 ms | 10588 KB | Output is correct |
19 | Correct | 2 ms | 10588 KB | Output is correct |
20 | Correct | 2 ms | 10588 KB | Output is correct |
21 | Correct | 2 ms | 10588 KB | Output is correct |
22 | Correct | 2 ms | 10588 KB | Output is correct |
23 | Correct | 2 ms | 10588 KB | Output is correct |
24 | Correct | 2 ms | 10676 KB | Output is correct |
25 | Correct | 2 ms | 10584 KB | Output is correct |
26 | Correct | 17 ms | 12632 KB | Output is correct |
27 | Correct | 17 ms | 12636 KB | Output is correct |
28 | Correct | 16 ms | 12636 KB | Output is correct |
29 | Correct | 16 ms | 12748 KB | Output is correct |
30 | Correct | 16 ms | 12632 KB | Output is correct |
31 | Correct | 30 ms | 15708 KB | Output is correct |
32 | Correct | 32 ms | 15964 KB | Output is correct |
33 | Correct | 31 ms | 15980 KB | Output is correct |
34 | Correct | 31 ms | 15964 KB | Output is correct |
35 | Correct | 31 ms | 15940 KB | Output is correct |
36 | Correct | 39 ms | 15696 KB | Output is correct |
37 | Correct | 32 ms | 15696 KB | Output is correct |
38 | Correct | 32 ms | 15952 KB | Output is correct |
39 | Correct | 31 ms | 15708 KB | Output is correct |
40 | Correct | 33 ms | 15956 KB | Output is correct |
41 | Correct | 15 ms | 12632 KB | Output is correct |
42 | Correct | 15 ms | 12632 KB | Output is correct |
43 | Correct | 15 ms | 12632 KB | Output is correct |
44 | Correct | 16 ms | 12636 KB | Output is correct |
45 | Correct | 15 ms | 12736 KB | Output is correct |
46 | Correct | 20 ms | 12636 KB | Output is correct |
47 | Correct | 15 ms | 12636 KB | Output is correct |
48 | Correct | 15 ms | 12636 KB | Output is correct |
49 | Correct | 14 ms | 12740 KB | Output is correct |
50 | Correct | 16 ms | 12636 KB | Output is correct |
51 | Correct | 40 ms | 15696 KB | Output is correct |
52 | Correct | 39 ms | 15440 KB | Output is correct |
53 | Correct | 38 ms | 15708 KB | Output is correct |
54 | Correct | 38 ms | 15476 KB | Output is correct |
55 | Correct | 40 ms | 15728 KB | Output is correct |
56 | Correct | 440 ms | 46964 KB | Output is correct |
57 | Correct | 434 ms | 59052 KB | Output is correct |
58 | Correct | 421 ms | 58156 KB | Output is correct |
59 | Correct | 420 ms | 58332 KB | Output is correct |
60 | Correct | 451 ms | 60500 KB | Output is correct |