Submission #943174

# Submission time Handle Problem Language Result Execution time Memory
943174 2024-03-11T09:03:35 Z Lilypad Pilot (NOI19_pilot) C++14
40 / 100
156 ms 15744 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,ans,tmp;
ll sz[N],par[N],ansq[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 1 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 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 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 10588 KB Output is correct
4 Correct 1 ms 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 2 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 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 10588 KB Output is correct
4 Correct 1 ms 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 2 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 2 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 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 1 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 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 2 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 2 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 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 10736 KB Output is correct
22 Correct 4 ms 10588 KB Output is correct
23 Correct 3 ms 10584 KB Output is correct
24 Correct 4 ms 10584 KB Output is correct
25 Correct 4 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 156 ms 15744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 15696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 10588 KB Output is correct
4 Correct 1 ms 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Incorrect 16 ms 12636 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 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 10588 KB Output is correct
4 Correct 1 ms 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 2 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 2 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 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 10736 KB Output is correct
22 Correct 4 ms 10588 KB Output is correct
23 Correct 3 ms 10584 KB Output is correct
24 Correct 4 ms 10584 KB Output is correct
25 Correct 4 ms 10584 KB Output is correct
26 Incorrect 16 ms 12636 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 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 10588 KB Output is correct
4 Correct 1 ms 10632 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 10716 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 2 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 2 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 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 10736 KB Output is correct
22 Correct 4 ms 10588 KB Output is correct
23 Correct 3 ms 10584 KB Output is correct
24 Correct 4 ms 10584 KB Output is correct
25 Correct 4 ms 10584 KB Output is correct
26 Incorrect 16 ms 12636 KB Output isn't correct
27 Halted 0 ms 0 KB -