답안 #943197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943197 2024-03-11T09:11:59 Z Lilypad Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 44620 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10584 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 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10584 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 1 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 10588 KB Output is correct
24 Correct 3 ms 10584 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12632 KB Output is correct
2 Correct 16 ms 12632 KB Output is correct
3 Correct 15 ms 12636 KB Output is correct
4 Correct 15 ms 12636 KB Output is correct
5 Correct 15 ms 12632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 15956 KB Output is correct
2 Correct 128 ms 15952 KB Output is correct
3 Correct 128 ms 15916 KB Output is correct
4 Correct 128 ms 15852 KB Output is correct
5 Correct 128 ms 15968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 15756 KB Output is correct
2 Correct 124 ms 15696 KB Output is correct
3 Correct 128 ms 15828 KB Output is correct
4 Correct 122 ms 15860 KB Output is correct
5 Correct 135 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 17 ms 12632 KB Output is correct
12 Correct 16 ms 12632 KB Output is correct
13 Correct 15 ms 12636 KB Output is correct
14 Correct 15 ms 12636 KB Output is correct
15 Correct 15 ms 12632 KB Output is correct
16 Correct 15 ms 12632 KB Output is correct
17 Correct 16 ms 12636 KB Output is correct
18 Correct 14 ms 12636 KB Output is correct
19 Correct 13 ms 12632 KB Output is correct
20 Correct 14 ms 12632 KB Output is correct
21 Correct 15 ms 12632 KB Output is correct
22 Correct 13 ms 12636 KB Output is correct
23 Correct 14 ms 12768 KB Output is correct
24 Correct 14 ms 12636 KB Output is correct
25 Correct 14 ms 12768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10584 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 1 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 10588 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 12632 KB Output is correct
27 Correct 16 ms 12632 KB Output is correct
28 Correct 15 ms 12636 KB Output is correct
29 Correct 15 ms 12636 KB Output is correct
30 Correct 15 ms 12632 KB Output is correct
31 Correct 122 ms 15956 KB Output is correct
32 Correct 128 ms 15952 KB Output is correct
33 Correct 128 ms 15916 KB Output is correct
34 Correct 128 ms 15852 KB Output is correct
35 Correct 128 ms 15968 KB Output is correct
36 Correct 121 ms 15756 KB Output is correct
37 Correct 124 ms 15696 KB Output is correct
38 Correct 128 ms 15828 KB Output is correct
39 Correct 122 ms 15860 KB Output is correct
40 Correct 135 ms 15956 KB Output is correct
41 Correct 15 ms 12632 KB Output is correct
42 Correct 16 ms 12636 KB Output is correct
43 Correct 14 ms 12636 KB Output is correct
44 Correct 13 ms 12632 KB Output is correct
45 Correct 14 ms 12632 KB Output is correct
46 Correct 15 ms 12632 KB Output is correct
47 Correct 13 ms 12636 KB Output is correct
48 Correct 14 ms 12768 KB Output is correct
49 Correct 14 ms 12636 KB Output is correct
50 Correct 14 ms 12768 KB Output is correct
51 Correct 134 ms 15560 KB Output is correct
52 Correct 134 ms 15440 KB Output is correct
53 Correct 133 ms 15700 KB Output is correct
54 Correct 131 ms 15440 KB Output is correct
55 Correct 136 ms 15696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 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 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10584 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 1 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 10588 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 12632 KB Output is correct
27 Correct 16 ms 12632 KB Output is correct
28 Correct 15 ms 12636 KB Output is correct
29 Correct 15 ms 12636 KB Output is correct
30 Correct 15 ms 12632 KB Output is correct
31 Correct 122 ms 15956 KB Output is correct
32 Correct 128 ms 15952 KB Output is correct
33 Correct 128 ms 15916 KB Output is correct
34 Correct 128 ms 15852 KB Output is correct
35 Correct 128 ms 15968 KB Output is correct
36 Correct 121 ms 15756 KB Output is correct
37 Correct 124 ms 15696 KB Output is correct
38 Correct 128 ms 15828 KB Output is correct
39 Correct 122 ms 15860 KB Output is correct
40 Correct 135 ms 15956 KB Output is correct
41 Correct 15 ms 12632 KB Output is correct
42 Correct 16 ms 12636 KB Output is correct
43 Correct 14 ms 12636 KB Output is correct
44 Correct 13 ms 12632 KB Output is correct
45 Correct 14 ms 12632 KB Output is correct
46 Correct 15 ms 12632 KB Output is correct
47 Correct 13 ms 12636 KB Output is correct
48 Correct 14 ms 12768 KB Output is correct
49 Correct 14 ms 12636 KB Output is correct
50 Correct 14 ms 12768 KB Output is correct
51 Correct 134 ms 15560 KB Output is correct
52 Correct 134 ms 15440 KB Output is correct
53 Correct 133 ms 15700 KB Output is correct
54 Correct 131 ms 15440 KB Output is correct
55 Correct 136 ms 15696 KB Output is correct
56 Execution timed out 1072 ms 44620 KB Time limit exceeded
57 Halted 0 ms 0 KB -