Submission #253207

# Submission time Handle Problem Language Result Execution time Memory
253207 2020-07-27T12:10:20 Z nandonathaniel Pilot (NOI19_pilot) C++14
100 / 100
597 ms 60920 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const LL MAXN=1000005;
pii arr[MAXN];
bool ada[MAXN];
LL par[MAXN],sz[MAXN],ans[MAXN];

LL find(LL x){
	if(par[x]==x)return par[x];
	return par[x]=find(par[x]);
}

void join(LL u,LL v){
	LL repu=find(u),repv=find(v);
	par[repu]=repv;
	sz[repv]+=sz[repu];
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	LL n,q,h;
	cin >> n >> q;
	for(LL i=1;i<=n;i++){
		cin >> h;
		arr[i]={h,i};
		par[i]=i;
		sz[i]=1;
	}
	sort(arr+1,arr+n+1);
	for(LL i=1;i<=n;i++){
		pii isi=arr[i];
		LL kiri=0,kanan=0;
		if(ada[isi.second-1]){
			kiri=sz[find(isi.second-1)];
			join(isi.second,isi.second-1);
		}
		if(ada[isi.second+1]){
			kanan=sz[find(isi.second+1)];
			join(isi.second,isi.second+1);
		}
		ada[isi.second]=true;
		ans[isi.first]+=(kiri+1)*(kanan+1);
	}
	for(LL i=1;i<=MAXN;i++)ans[i]+=ans[i-1];
	while(q--){
		cin >> h;
		cout << ans[h] << '\n';
	}
	return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:46:31: warning: iteration 1000004 invokes undefined behavior [-Waggressive-loop-optimizations]
  for(LL i=1;i<=MAXN;i++)ans[i]+=ans[i-1];
                         ~~~~~~^~~~~~~~~~
pilot.cpp:46:14: note: within this loop
  for(LL i=1;i<=MAXN;i++)ans[i]+=ans[i-1];
             ~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
11 Correct 6 ms 8192 KB Output is correct
12 Correct 6 ms 8192 KB Output is correct
13 Correct 6 ms 8192 KB Output is correct
14 Correct 7 ms 8184 KB Output is correct
15 Correct 6 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
11 Correct 6 ms 8192 KB Output is correct
12 Correct 6 ms 8192 KB Output is correct
13 Correct 6 ms 8192 KB Output is correct
14 Correct 7 ms 8184 KB Output is correct
15 Correct 6 ms 8192 KB Output is correct
16 Correct 6 ms 8192 KB Output is correct
17 Correct 6 ms 8192 KB Output is correct
18 Correct 6 ms 8192 KB Output is correct
19 Correct 7 ms 8192 KB Output is correct
20 Correct 6 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
11 Correct 6 ms 8192 KB Output is correct
12 Correct 6 ms 8192 KB Output is correct
13 Correct 6 ms 8192 KB Output is correct
14 Correct 7 ms 8184 KB Output is correct
15 Correct 6 ms 8192 KB Output is correct
16 Correct 6 ms 8192 KB Output is correct
17 Correct 6 ms 8192 KB Output is correct
18 Correct 6 ms 8192 KB Output is correct
19 Correct 7 ms 8192 KB Output is correct
20 Correct 6 ms 8192 KB Output is correct
21 Correct 7 ms 8192 KB Output is correct
22 Correct 7 ms 8192 KB Output is correct
23 Correct 7 ms 8192 KB Output is correct
24 Correct 7 ms 8192 KB Output is correct
25 Correct 7 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 11860 KB Output is correct
2 Correct 32 ms 12024 KB Output is correct
3 Correct 32 ms 11768 KB Output is correct
4 Correct 27 ms 11640 KB Output is correct
5 Correct 29 ms 11768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 13304 KB Output is correct
2 Correct 43 ms 13304 KB Output is correct
3 Correct 41 ms 13304 KB Output is correct
4 Correct 43 ms 13432 KB Output is correct
5 Correct 44 ms 13176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 13432 KB Output is correct
2 Correct 44 ms 13400 KB Output is correct
3 Correct 47 ms 13560 KB Output is correct
4 Correct 46 ms 13688 KB Output is correct
5 Correct 47 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
11 Correct 30 ms 11860 KB Output is correct
12 Correct 32 ms 12024 KB Output is correct
13 Correct 32 ms 11768 KB Output is correct
14 Correct 27 ms 11640 KB Output is correct
15 Correct 29 ms 11768 KB Output is correct
16 Correct 30 ms 11640 KB Output is correct
17 Correct 32 ms 12024 KB Output is correct
18 Correct 31 ms 12024 KB Output is correct
19 Correct 29 ms 11784 KB Output is correct
20 Correct 30 ms 11896 KB Output is correct
21 Correct 29 ms 11776 KB Output is correct
22 Correct 28 ms 11768 KB Output is correct
23 Correct 30 ms 12024 KB Output is correct
24 Correct 28 ms 11768 KB Output is correct
25 Correct 29 ms 11880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
11 Correct 6 ms 8192 KB Output is correct
12 Correct 6 ms 8192 KB Output is correct
13 Correct 6 ms 8192 KB Output is correct
14 Correct 7 ms 8184 KB Output is correct
15 Correct 6 ms 8192 KB Output is correct
16 Correct 6 ms 8192 KB Output is correct
17 Correct 6 ms 8192 KB Output is correct
18 Correct 6 ms 8192 KB Output is correct
19 Correct 7 ms 8192 KB Output is correct
20 Correct 6 ms 8192 KB Output is correct
21 Correct 7 ms 8192 KB Output is correct
22 Correct 7 ms 8192 KB Output is correct
23 Correct 7 ms 8192 KB Output is correct
24 Correct 7 ms 8192 KB Output is correct
25 Correct 7 ms 8192 KB Output is correct
26 Correct 30 ms 11860 KB Output is correct
27 Correct 32 ms 12024 KB Output is correct
28 Correct 32 ms 11768 KB Output is correct
29 Correct 27 ms 11640 KB Output is correct
30 Correct 29 ms 11768 KB Output is correct
31 Correct 41 ms 13304 KB Output is correct
32 Correct 43 ms 13304 KB Output is correct
33 Correct 41 ms 13304 KB Output is correct
34 Correct 43 ms 13432 KB Output is correct
35 Correct 44 ms 13176 KB Output is correct
36 Correct 46 ms 13432 KB Output is correct
37 Correct 44 ms 13400 KB Output is correct
38 Correct 47 ms 13560 KB Output is correct
39 Correct 46 ms 13688 KB Output is correct
40 Correct 47 ms 13560 KB Output is correct
41 Correct 30 ms 11640 KB Output is correct
42 Correct 32 ms 12024 KB Output is correct
43 Correct 31 ms 12024 KB Output is correct
44 Correct 29 ms 11784 KB Output is correct
45 Correct 30 ms 11896 KB Output is correct
46 Correct 29 ms 11776 KB Output is correct
47 Correct 28 ms 11768 KB Output is correct
48 Correct 30 ms 12024 KB Output is correct
49 Correct 28 ms 11768 KB Output is correct
50 Correct 29 ms 11880 KB Output is correct
51 Correct 54 ms 13316 KB Output is correct
52 Correct 61 ms 13176 KB Output is correct
53 Correct 55 ms 13432 KB Output is correct
54 Correct 62 ms 13176 KB Output is correct
55 Correct 53 ms 13304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 6 ms 8192 KB Output is correct
4 Correct 6 ms 8192 KB Output is correct
5 Correct 6 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 6 ms 8192 KB Output is correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 6 ms 8192 KB Output is correct
10 Correct 6 ms 8192 KB Output is correct
11 Correct 6 ms 8192 KB Output is correct
12 Correct 6 ms 8192 KB Output is correct
13 Correct 6 ms 8192 KB Output is correct
14 Correct 7 ms 8184 KB Output is correct
15 Correct 6 ms 8192 KB Output is correct
16 Correct 6 ms 8192 KB Output is correct
17 Correct 6 ms 8192 KB Output is correct
18 Correct 6 ms 8192 KB Output is correct
19 Correct 7 ms 8192 KB Output is correct
20 Correct 6 ms 8192 KB Output is correct
21 Correct 7 ms 8192 KB Output is correct
22 Correct 7 ms 8192 KB Output is correct
23 Correct 7 ms 8192 KB Output is correct
24 Correct 7 ms 8192 KB Output is correct
25 Correct 7 ms 8192 KB Output is correct
26 Correct 30 ms 11860 KB Output is correct
27 Correct 32 ms 12024 KB Output is correct
28 Correct 32 ms 11768 KB Output is correct
29 Correct 27 ms 11640 KB Output is correct
30 Correct 29 ms 11768 KB Output is correct
31 Correct 41 ms 13304 KB Output is correct
32 Correct 43 ms 13304 KB Output is correct
33 Correct 41 ms 13304 KB Output is correct
34 Correct 43 ms 13432 KB Output is correct
35 Correct 44 ms 13176 KB Output is correct
36 Correct 46 ms 13432 KB Output is correct
37 Correct 44 ms 13400 KB Output is correct
38 Correct 47 ms 13560 KB Output is correct
39 Correct 46 ms 13688 KB Output is correct
40 Correct 47 ms 13560 KB Output is correct
41 Correct 30 ms 11640 KB Output is correct
42 Correct 32 ms 12024 KB Output is correct
43 Correct 31 ms 12024 KB Output is correct
44 Correct 29 ms 11784 KB Output is correct
45 Correct 30 ms 11896 KB Output is correct
46 Correct 29 ms 11776 KB Output is correct
47 Correct 28 ms 11768 KB Output is correct
48 Correct 30 ms 12024 KB Output is correct
49 Correct 28 ms 11768 KB Output is correct
50 Correct 29 ms 11880 KB Output is correct
51 Correct 54 ms 13316 KB Output is correct
52 Correct 61 ms 13176 KB Output is correct
53 Correct 55 ms 13432 KB Output is correct
54 Correct 62 ms 13176 KB Output is correct
55 Correct 53 ms 13304 KB Output is correct
56 Correct 597 ms 59152 KB Output is correct
57 Correct 580 ms 60024 KB Output is correct
58 Correct 552 ms 56672 KB Output is correct
59 Correct 512 ms 57720 KB Output is correct
60 Correct 581 ms 60920 KB Output is correct