Submission #224487

# Submission time Handle Problem Language Result Execution time Memory
224487 2020-04-18T05:08:49 Z maximath_1 Pilot (NOI19_pilot) C++14
100 / 100
970 ms 45116 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=1e6+5;
int n, q, par[mxn], sz[mxn];
pair<int, int>h[mxn];
bool vis[mxn];
int f(int a){return par[a]=(par[a]==a)?a:f(par[a]);}
ll calc(int x){return (ll)sz[f(x)]*(sz[f(x)]+1)/2;}
int main(){
	scanf("%d%d", &n, &q);
	for(int i=0; i<n; i++){
		scanf("%d", &h[i].first);
		h[i].second=i; par[i]=i;
		vis[i]=false; sz[i]=1;
	}
	vector<ll>val;
	vector<int>id;
	id.push_back(0); val.push_back(0ll);
	sort(h, h+n);
	ll v=0ll, vt=0ll; int tmp=h[0].first;
	for(int i=0; i<n; i++){
		if(h[i].second>0 && vis[h[i].second-1]){
			int uu=h[i].second, vv=h[i].second-1;
			v-=calc(vv);
			uu=f(uu); vv=f(vv);
			sz[uu]+=sz[vv]; par[vv]=uu;
		}
		if(h[i].second<n-1 && vis[h[i].second+1]){
			int uu=h[i].second, vv=h[i].second+1;
			v-=calc(vv);
			uu=f(uu); vv=f(vv);
			sz[uu]+=sz[vv]; par[vv]=uu;
		}
		v+=calc(h[i].second);
		if(tmp!=h[i].first){
			id.push_back(tmp);
			val.push_back(vt);
			tmp=h[i].first;
		}
		vt=v; vis[h[i].second]=true;
	}
	id.push_back(tmp);
	val.push_back(vt);
	for(int i=0, h; i<q; i++){
		scanf("%d", &h);
		int ii=lower_bound(id.begin(), id.end(), h)-id.begin();
		if(id[ii]!=h) ii--;
		printf("%lld\n", val[ii]);
	}
	return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~
pilot.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &h[i].first);
   ~~~~~^~~~~~~~~~~~~~~~~~~
pilot.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &h);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3440 KB Output is correct
2 Correct 36 ms 4204 KB Output is correct
3 Correct 34 ms 3324 KB Output is correct
4 Correct 33 ms 3948 KB Output is correct
5 Correct 34 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 5476 KB Output is correct
2 Correct 62 ms 5352 KB Output is correct
3 Correct 61 ms 5220 KB Output is correct
4 Correct 64 ms 5476 KB Output is correct
5 Correct 61 ms 5220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 5476 KB Output is correct
2 Correct 67 ms 5480 KB Output is correct
3 Correct 71 ms 5348 KB Output is correct
4 Correct 67 ms 5604 KB Output is correct
5 Correct 72 ms 5604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 34 ms 3440 KB Output is correct
12 Correct 36 ms 4204 KB Output is correct
13 Correct 34 ms 3324 KB Output is correct
14 Correct 33 ms 3948 KB Output is correct
15 Correct 34 ms 3316 KB Output is correct
16 Correct 33 ms 3316 KB Output is correct
17 Correct 35 ms 4076 KB Output is correct
18 Correct 36 ms 4204 KB Output is correct
19 Correct 33 ms 3324 KB Output is correct
20 Correct 36 ms 4076 KB Output is correct
21 Correct 34 ms 3320 KB Output is correct
22 Correct 34 ms 4084 KB Output is correct
23 Correct 37 ms 3576 KB Output is correct
24 Correct 33 ms 3956 KB Output is correct
25 Correct 35 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 34 ms 3440 KB Output is correct
27 Correct 36 ms 4204 KB Output is correct
28 Correct 34 ms 3324 KB Output is correct
29 Correct 33 ms 3948 KB Output is correct
30 Correct 34 ms 3316 KB Output is correct
31 Correct 62 ms 5476 KB Output is correct
32 Correct 62 ms 5352 KB Output is correct
33 Correct 61 ms 5220 KB Output is correct
34 Correct 64 ms 5476 KB Output is correct
35 Correct 61 ms 5220 KB Output is correct
36 Correct 68 ms 5476 KB Output is correct
37 Correct 67 ms 5480 KB Output is correct
38 Correct 71 ms 5348 KB Output is correct
39 Correct 67 ms 5604 KB Output is correct
40 Correct 72 ms 5604 KB Output is correct
41 Correct 33 ms 3316 KB Output is correct
42 Correct 35 ms 4076 KB Output is correct
43 Correct 36 ms 4204 KB Output is correct
44 Correct 33 ms 3324 KB Output is correct
45 Correct 36 ms 4076 KB Output is correct
46 Correct 34 ms 3320 KB Output is correct
47 Correct 34 ms 4084 KB Output is correct
48 Correct 37 ms 3576 KB Output is correct
49 Correct 33 ms 3956 KB Output is correct
50 Correct 35 ms 3448 KB Output is correct
51 Correct 78 ms 4848 KB Output is correct
52 Correct 86 ms 5096 KB Output is correct
53 Correct 72 ms 4976 KB Output is correct
54 Correct 77 ms 5092 KB Output is correct
55 Correct 72 ms 4848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 34 ms 3440 KB Output is correct
27 Correct 36 ms 4204 KB Output is correct
28 Correct 34 ms 3324 KB Output is correct
29 Correct 33 ms 3948 KB Output is correct
30 Correct 34 ms 3316 KB Output is correct
31 Correct 62 ms 5476 KB Output is correct
32 Correct 62 ms 5352 KB Output is correct
33 Correct 61 ms 5220 KB Output is correct
34 Correct 64 ms 5476 KB Output is correct
35 Correct 61 ms 5220 KB Output is correct
36 Correct 68 ms 5476 KB Output is correct
37 Correct 67 ms 5480 KB Output is correct
38 Correct 71 ms 5348 KB Output is correct
39 Correct 67 ms 5604 KB Output is correct
40 Correct 72 ms 5604 KB Output is correct
41 Correct 33 ms 3316 KB Output is correct
42 Correct 35 ms 4076 KB Output is correct
43 Correct 36 ms 4204 KB Output is correct
44 Correct 33 ms 3324 KB Output is correct
45 Correct 36 ms 4076 KB Output is correct
46 Correct 34 ms 3320 KB Output is correct
47 Correct 34 ms 4084 KB Output is correct
48 Correct 37 ms 3576 KB Output is correct
49 Correct 33 ms 3956 KB Output is correct
50 Correct 35 ms 3448 KB Output is correct
51 Correct 78 ms 4848 KB Output is correct
52 Correct 86 ms 5096 KB Output is correct
53 Correct 72 ms 4976 KB Output is correct
54 Correct 77 ms 5092 KB Output is correct
55 Correct 72 ms 4848 KB Output is correct
56 Correct 970 ms 43708 KB Output is correct
57 Correct 936 ms 44340 KB Output is correct
58 Correct 862 ms 41536 KB Output is correct
59 Correct 880 ms 42684 KB Output is correct
60 Correct 951 ms 45116 KB Output is correct