Submission #943188

# Submission time Handle Problem Language Result Execution time Memory
943188 2024-03-11T09:07:39 Z Lilypad Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 51252 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);
	cin >> n >> q;
	for(int i=1; i<=n; i++) {
		cin >> 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++) {
		cin >> 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++) cout << ansq[i] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 10588 KB Output is correct
12 Correct 2 ms 10584 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 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 10588 KB Output is correct
12 Correct 2 ms 10584 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 10584 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 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 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 10588 KB Output is correct
12 Correct 2 ms 10584 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 10584 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 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 3 ms 10588 KB Output is correct
22 Correct 3 ms 10588 KB Output is correct
23 Correct 3 ms 10712 KB Output is correct
24 Correct 3 ms 10584 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 13172 KB Output is correct
2 Correct 17 ms 13276 KB Output is correct
3 Correct 16 ms 13148 KB Output is correct
4 Correct 15 ms 13148 KB Output is correct
5 Correct 15 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 16572 KB Output is correct
2 Correct 128 ms 16724 KB Output is correct
3 Correct 135 ms 16608 KB Output is correct
4 Correct 125 ms 16720 KB Output is correct
5 Correct 126 ms 16592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 16468 KB Output is correct
2 Correct 126 ms 16468 KB Output is correct
3 Correct 146 ms 16576 KB Output is correct
4 Correct 121 ms 16760 KB Output is correct
5 Correct 133 ms 16836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 13172 KB Output is correct
12 Correct 17 ms 13276 KB Output is correct
13 Correct 16 ms 13148 KB Output is correct
14 Correct 15 ms 13148 KB Output is correct
15 Correct 15 ms 13148 KB Output is correct
16 Correct 16 ms 13276 KB Output is correct
17 Correct 14 ms 13140 KB Output is correct
18 Correct 15 ms 13140 KB Output is correct
19 Correct 13 ms 13144 KB Output is correct
20 Correct 15 ms 13140 KB Output is correct
21 Correct 15 ms 13148 KB Output is correct
22 Correct 14 ms 13144 KB Output is correct
23 Correct 14 ms 13148 KB Output is correct
24 Correct 14 ms 13144 KB Output is correct
25 Correct 14 ms 13288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 10588 KB Output is correct
12 Correct 2 ms 10584 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 10584 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 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 3 ms 10588 KB Output is correct
22 Correct 3 ms 10588 KB Output is correct
23 Correct 3 ms 10712 KB Output is correct
24 Correct 3 ms 10584 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 17 ms 13172 KB Output is correct
27 Correct 17 ms 13276 KB Output is correct
28 Correct 16 ms 13148 KB Output is correct
29 Correct 15 ms 13148 KB Output is correct
30 Correct 15 ms 13148 KB Output is correct
31 Correct 123 ms 16572 KB Output is correct
32 Correct 128 ms 16724 KB Output is correct
33 Correct 135 ms 16608 KB Output is correct
34 Correct 125 ms 16720 KB Output is correct
35 Correct 126 ms 16592 KB Output is correct
36 Correct 126 ms 16468 KB Output is correct
37 Correct 126 ms 16468 KB Output is correct
38 Correct 146 ms 16576 KB Output is correct
39 Correct 121 ms 16760 KB Output is correct
40 Correct 133 ms 16836 KB Output is correct
41 Correct 16 ms 13276 KB Output is correct
42 Correct 14 ms 13140 KB Output is correct
43 Correct 15 ms 13140 KB Output is correct
44 Correct 13 ms 13144 KB Output is correct
45 Correct 15 ms 13140 KB Output is correct
46 Correct 15 ms 13148 KB Output is correct
47 Correct 14 ms 13144 KB Output is correct
48 Correct 14 ms 13148 KB Output is correct
49 Correct 14 ms 13144 KB Output is correct
50 Correct 14 ms 13288 KB Output is correct
51 Correct 139 ms 16732 KB Output is correct
52 Correct 141 ms 16464 KB Output is correct
53 Correct 163 ms 16464 KB Output is correct
54 Correct 133 ms 16152 KB Output is correct
55 Correct 131 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 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 8792 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10704 KB Output is correct
8 Correct 2 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 10588 KB Output is correct
12 Correct 2 ms 10584 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 10584 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 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 3 ms 10588 KB Output is correct
22 Correct 3 ms 10588 KB Output is correct
23 Correct 3 ms 10712 KB Output is correct
24 Correct 3 ms 10584 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 17 ms 13172 KB Output is correct
27 Correct 17 ms 13276 KB Output is correct
28 Correct 16 ms 13148 KB Output is correct
29 Correct 15 ms 13148 KB Output is correct
30 Correct 15 ms 13148 KB Output is correct
31 Correct 123 ms 16572 KB Output is correct
32 Correct 128 ms 16724 KB Output is correct
33 Correct 135 ms 16608 KB Output is correct
34 Correct 125 ms 16720 KB Output is correct
35 Correct 126 ms 16592 KB Output is correct
36 Correct 126 ms 16468 KB Output is correct
37 Correct 126 ms 16468 KB Output is correct
38 Correct 146 ms 16576 KB Output is correct
39 Correct 121 ms 16760 KB Output is correct
40 Correct 133 ms 16836 KB Output is correct
41 Correct 16 ms 13276 KB Output is correct
42 Correct 14 ms 13140 KB Output is correct
43 Correct 15 ms 13140 KB Output is correct
44 Correct 13 ms 13144 KB Output is correct
45 Correct 15 ms 13140 KB Output is correct
46 Correct 15 ms 13148 KB Output is correct
47 Correct 14 ms 13144 KB Output is correct
48 Correct 14 ms 13148 KB Output is correct
49 Correct 14 ms 13144 KB Output is correct
50 Correct 14 ms 13288 KB Output is correct
51 Correct 139 ms 16732 KB Output is correct
52 Correct 141 ms 16464 KB Output is correct
53 Correct 163 ms 16464 KB Output is correct
54 Correct 133 ms 16152 KB Output is correct
55 Correct 131 ms 16376 KB Output is correct
56 Execution timed out 1095 ms 51252 KB Time limit exceeded
57 Halted 0 ms 0 KB -