Submission #901341

# Submission time Handle Problem Language Result Execution time Memory
901341 2024-01-09T10:51:17 Z pcc Pilot (NOI19_pilot) C++14
100 / 100
418 ms 52836 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 1e6+10;
int dsu[mxn],sz[mxn];
ll ans[mxn],sum;
bitset<mxn> active;
vector<pii> op;
int n,q;

int root(int k){
	return k == dsu[k]?k:dsu[k] = root(dsu[k]);
}
void onion(int a,int b){
	a = root(a),b = root(b);
	if(a == b)return;
	sum -= 1ll*(sz[a]-1)*sz[a]/2;
	sum -= 1ll*sz[b]*(sz[b]-1)/2;
	sz[a] += sz[b];
	dsu[b] = a;
	sum += 1ll*sz[a]*(sz[a]-1)/2;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for(int i = 1;i<=n;i++){
		int k;
		cin>>k;
		op.push_back(make_pair(k,-i));
		dsu[i] = i,sz[i] = 1;
	}
	for(int i = 1;i<=q;i++){
		int k;
		cin>>k;
		op.push_back({k,i});
	}
	sort(op.begin(),op.end());
	for(auto &i:op){
		if(i.sc<0){
			i.sc = -i.sc;
			active[i.sc] = true;
			sum++;
			if(active[i.sc-1])onion(i.sc-1,i.sc);
			if(active[i.sc+1])onion(i.sc,i.sc+1);
		}
		else{
			ans[i.sc] = sum;
		}
	}
	for(int i = 1;i<=q;i++)cout<<ans[i]<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4692 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6108 KB Output is correct
2 Correct 16 ms 6616 KB Output is correct
3 Correct 16 ms 6108 KB Output is correct
4 Correct 15 ms 6108 KB Output is correct
5 Correct 16 ms 6108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 10464 KB Output is correct
2 Correct 35 ms 10444 KB Output is correct
3 Correct 33 ms 10408 KB Output is correct
4 Correct 34 ms 10404 KB Output is correct
5 Correct 34 ms 10340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 10444 KB Output is correct
2 Correct 35 ms 10452 KB Output is correct
3 Correct 37 ms 10440 KB Output is correct
4 Correct 34 ms 10436 KB Output is correct
5 Correct 49 ms 11040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 16 ms 6108 KB Output is correct
12 Correct 16 ms 6616 KB Output is correct
13 Correct 16 ms 6108 KB Output is correct
14 Correct 15 ms 6108 KB Output is correct
15 Correct 16 ms 6108 KB Output is correct
16 Correct 16 ms 6104 KB Output is correct
17 Correct 22 ms 6364 KB Output is correct
18 Correct 23 ms 6364 KB Output is correct
19 Correct 19 ms 6236 KB Output is correct
20 Correct 22 ms 6352 KB Output is correct
21 Correct 15 ms 6108 KB Output is correct
22 Correct 16 ms 6156 KB Output is correct
23 Correct 17 ms 6108 KB Output is correct
24 Correct 16 ms 6364 KB Output is correct
25 Correct 17 ms 6140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4692 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 16 ms 6108 KB Output is correct
27 Correct 16 ms 6616 KB Output is correct
28 Correct 16 ms 6108 KB Output is correct
29 Correct 15 ms 6108 KB Output is correct
30 Correct 16 ms 6108 KB Output is correct
31 Correct 32 ms 10464 KB Output is correct
32 Correct 35 ms 10444 KB Output is correct
33 Correct 33 ms 10408 KB Output is correct
34 Correct 34 ms 10404 KB Output is correct
35 Correct 34 ms 10340 KB Output is correct
36 Correct 33 ms 10444 KB Output is correct
37 Correct 35 ms 10452 KB Output is correct
38 Correct 37 ms 10440 KB Output is correct
39 Correct 34 ms 10436 KB Output is correct
40 Correct 49 ms 11040 KB Output is correct
41 Correct 16 ms 6104 KB Output is correct
42 Correct 22 ms 6364 KB Output is correct
43 Correct 23 ms 6364 KB Output is correct
44 Correct 19 ms 6236 KB Output is correct
45 Correct 22 ms 6352 KB Output is correct
46 Correct 15 ms 6108 KB Output is correct
47 Correct 16 ms 6156 KB Output is correct
48 Correct 17 ms 6108 KB Output is correct
49 Correct 16 ms 6364 KB Output is correct
50 Correct 17 ms 6140 KB Output is correct
51 Correct 41 ms 10188 KB Output is correct
52 Correct 39 ms 10084 KB Output is correct
53 Correct 46 ms 10188 KB Output is correct
54 Correct 37 ms 10196 KB Output is correct
55 Correct 39 ms 10168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4692 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 16 ms 6108 KB Output is correct
27 Correct 16 ms 6616 KB Output is correct
28 Correct 16 ms 6108 KB Output is correct
29 Correct 15 ms 6108 KB Output is correct
30 Correct 16 ms 6108 KB Output is correct
31 Correct 32 ms 10464 KB Output is correct
32 Correct 35 ms 10444 KB Output is correct
33 Correct 33 ms 10408 KB Output is correct
34 Correct 34 ms 10404 KB Output is correct
35 Correct 34 ms 10340 KB Output is correct
36 Correct 33 ms 10444 KB Output is correct
37 Correct 35 ms 10452 KB Output is correct
38 Correct 37 ms 10440 KB Output is correct
39 Correct 34 ms 10436 KB Output is correct
40 Correct 49 ms 11040 KB Output is correct
41 Correct 16 ms 6104 KB Output is correct
42 Correct 22 ms 6364 KB Output is correct
43 Correct 23 ms 6364 KB Output is correct
44 Correct 19 ms 6236 KB Output is correct
45 Correct 22 ms 6352 KB Output is correct
46 Correct 15 ms 6108 KB Output is correct
47 Correct 16 ms 6156 KB Output is correct
48 Correct 17 ms 6108 KB Output is correct
49 Correct 16 ms 6364 KB Output is correct
50 Correct 17 ms 6140 KB Output is correct
51 Correct 41 ms 10188 KB Output is correct
52 Correct 39 ms 10084 KB Output is correct
53 Correct 46 ms 10188 KB Output is correct
54 Correct 37 ms 10196 KB Output is correct
55 Correct 39 ms 10168 KB Output is correct
56 Correct 418 ms 52136 KB Output is correct
57 Correct 417 ms 52344 KB Output is correct
58 Correct 392 ms 49520 KB Output is correct
59 Correct 410 ms 50104 KB Output is correct
60 Correct 418 ms 52836 KB Output is correct