Submission #572392

# Submission time Handle Problem Language Result Execution time Memory
572392 2022-06-04T10:30:35 Z MODDI Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 79724 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
const int maxn = 1e6 + 5;
int n, q;
vl arr;
ll parent[maxn];
ll sz[maxn];
bool on[maxn];
int find(int v){
	if(v == parent[v])
		return v;
	return parent[v] = find(parent[v]);
}
ll rez = 0;
void mrg(int a, int b){
	a = find(a);
	b = find(b);
	if(a != b){
		rez -= (sz[a] * (sz[a] + 1) * 1LL) / 2;
		rez -= (sz[b] * (sz[b] + 1)*1LL) / 2;
		sz[a] += sz[b];
		rez += (sz[a] * (sz[a] + 1)*1LL) / 2;
		parent[b] = a;
	}
}
vl G[maxn];
ll ans[maxn];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	arr.resize(n);
	for(int i = 0; i < n; i++){
		parent[i] = i;
		sz[i] = 1;
	}
	for(int i = 0; i < n; i++){
		cin>>arr[i];
		G[arr[i]].pb(i);
	}
	for(int i = 1; i <= 1000000; i++){
		for(int x : G[i]){
			++rez;
			on[x] = 1;
			if(x && on[x-1]) mrg(x, x-1);
			if(x != n-1 && on[x+1]) mrg(x, x + 1);
		}
		ans[i] = rez;
	}
	for(int i = 0; i < q; i++){
		ll a;
		cin>>a;
		cout<<ans[a]<<endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 17 ms 31724 KB Output is correct
13 Correct 18 ms 31672 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 19 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 17 ms 31724 KB Output is correct
13 Correct 18 ms 31672 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 19 ms 31572 KB Output is correct
16 Correct 19 ms 31572 KB Output is correct
17 Correct 17 ms 31544 KB Output is correct
18 Correct 16 ms 31572 KB Output is correct
19 Correct 17 ms 31580 KB Output is correct
20 Correct 18 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 17 ms 31724 KB Output is correct
13 Correct 18 ms 31672 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 19 ms 31572 KB Output is correct
16 Correct 19 ms 31572 KB Output is correct
17 Correct 17 ms 31544 KB Output is correct
18 Correct 16 ms 31572 KB Output is correct
19 Correct 17 ms 31580 KB Output is correct
20 Correct 18 ms 31572 KB Output is correct
21 Correct 18 ms 31584 KB Output is correct
22 Correct 19 ms 31660 KB Output is correct
23 Correct 19 ms 31700 KB Output is correct
24 Correct 18 ms 31700 KB Output is correct
25 Correct 19 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 36052 KB Output is correct
2 Correct 58 ms 36912 KB Output is correct
3 Correct 41 ms 35932 KB Output is correct
4 Correct 50 ms 36424 KB Output is correct
5 Correct 36 ms 35812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 37800 KB Output is correct
2 Correct 158 ms 37740 KB Output is correct
3 Correct 152 ms 37688 KB Output is correct
4 Correct 147 ms 37996 KB Output is correct
5 Correct 160 ms 37696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 37788 KB Output is correct
2 Correct 157 ms 37780 KB Output is correct
3 Correct 162 ms 37624 KB Output is correct
4 Correct 159 ms 38028 KB Output is correct
5 Correct 168 ms 37896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 36 ms 36052 KB Output is correct
12 Correct 58 ms 36912 KB Output is correct
13 Correct 41 ms 35932 KB Output is correct
14 Correct 50 ms 36424 KB Output is correct
15 Correct 36 ms 35812 KB Output is correct
16 Correct 37 ms 35796 KB Output is correct
17 Correct 48 ms 36948 KB Output is correct
18 Correct 52 ms 36956 KB Output is correct
19 Correct 37 ms 35752 KB Output is correct
20 Correct 50 ms 36768 KB Output is correct
21 Correct 36 ms 35752 KB Output is correct
22 Correct 49 ms 36576 KB Output is correct
23 Correct 46 ms 36112 KB Output is correct
24 Correct 49 ms 36508 KB Output is correct
25 Correct 37 ms 36024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 17 ms 31724 KB Output is correct
13 Correct 18 ms 31672 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 19 ms 31572 KB Output is correct
16 Correct 19 ms 31572 KB Output is correct
17 Correct 17 ms 31544 KB Output is correct
18 Correct 16 ms 31572 KB Output is correct
19 Correct 17 ms 31580 KB Output is correct
20 Correct 18 ms 31572 KB Output is correct
21 Correct 18 ms 31584 KB Output is correct
22 Correct 19 ms 31660 KB Output is correct
23 Correct 19 ms 31700 KB Output is correct
24 Correct 18 ms 31700 KB Output is correct
25 Correct 19 ms 31700 KB Output is correct
26 Correct 36 ms 36052 KB Output is correct
27 Correct 58 ms 36912 KB Output is correct
28 Correct 41 ms 35932 KB Output is correct
29 Correct 50 ms 36424 KB Output is correct
30 Correct 36 ms 35812 KB Output is correct
31 Correct 146 ms 37800 KB Output is correct
32 Correct 158 ms 37740 KB Output is correct
33 Correct 152 ms 37688 KB Output is correct
34 Correct 147 ms 37996 KB Output is correct
35 Correct 160 ms 37696 KB Output is correct
36 Correct 157 ms 37788 KB Output is correct
37 Correct 157 ms 37780 KB Output is correct
38 Correct 162 ms 37624 KB Output is correct
39 Correct 159 ms 38028 KB Output is correct
40 Correct 168 ms 37896 KB Output is correct
41 Correct 37 ms 35796 KB Output is correct
42 Correct 48 ms 36948 KB Output is correct
43 Correct 52 ms 36956 KB Output is correct
44 Correct 37 ms 35752 KB Output is correct
45 Correct 50 ms 36768 KB Output is correct
46 Correct 36 ms 35752 KB Output is correct
47 Correct 49 ms 36576 KB Output is correct
48 Correct 46 ms 36112 KB Output is correct
49 Correct 49 ms 36508 KB Output is correct
50 Correct 37 ms 36024 KB Output is correct
51 Correct 161 ms 36704 KB Output is correct
52 Correct 174 ms 37336 KB Output is correct
53 Correct 161 ms 36812 KB Output is correct
54 Correct 169 ms 37288 KB Output is correct
55 Correct 156 ms 36940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31572 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31572 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 18 ms 31600 KB Output is correct
7 Correct 16 ms 31600 KB Output is correct
8 Correct 17 ms 31536 KB Output is correct
9 Correct 16 ms 31608 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 17 ms 31724 KB Output is correct
13 Correct 18 ms 31672 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 19 ms 31572 KB Output is correct
16 Correct 19 ms 31572 KB Output is correct
17 Correct 17 ms 31544 KB Output is correct
18 Correct 16 ms 31572 KB Output is correct
19 Correct 17 ms 31580 KB Output is correct
20 Correct 18 ms 31572 KB Output is correct
21 Correct 18 ms 31584 KB Output is correct
22 Correct 19 ms 31660 KB Output is correct
23 Correct 19 ms 31700 KB Output is correct
24 Correct 18 ms 31700 KB Output is correct
25 Correct 19 ms 31700 KB Output is correct
26 Correct 36 ms 36052 KB Output is correct
27 Correct 58 ms 36912 KB Output is correct
28 Correct 41 ms 35932 KB Output is correct
29 Correct 50 ms 36424 KB Output is correct
30 Correct 36 ms 35812 KB Output is correct
31 Correct 146 ms 37800 KB Output is correct
32 Correct 158 ms 37740 KB Output is correct
33 Correct 152 ms 37688 KB Output is correct
34 Correct 147 ms 37996 KB Output is correct
35 Correct 160 ms 37696 KB Output is correct
36 Correct 157 ms 37788 KB Output is correct
37 Correct 157 ms 37780 KB Output is correct
38 Correct 162 ms 37624 KB Output is correct
39 Correct 159 ms 38028 KB Output is correct
40 Correct 168 ms 37896 KB Output is correct
41 Correct 37 ms 35796 KB Output is correct
42 Correct 48 ms 36948 KB Output is correct
43 Correct 52 ms 36956 KB Output is correct
44 Correct 37 ms 35752 KB Output is correct
45 Correct 50 ms 36768 KB Output is correct
46 Correct 36 ms 35752 KB Output is correct
47 Correct 49 ms 36576 KB Output is correct
48 Correct 46 ms 36112 KB Output is correct
49 Correct 49 ms 36508 KB Output is correct
50 Correct 37 ms 36024 KB Output is correct
51 Correct 161 ms 36704 KB Output is correct
52 Correct 174 ms 37336 KB Output is correct
53 Correct 161 ms 36812 KB Output is correct
54 Correct 169 ms 37288 KB Output is correct
55 Correct 156 ms 36940 KB Output is correct
56 Execution timed out 1093 ms 79724 KB Time limit exceeded
57 Halted 0 ms 0 KB -