답안 #224557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224557 2020-04-18T12:00:58 Z kshitij_sodani Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 51824 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
int par[1000001];
int ss[1000001];
int find(int no){

	if(par[no]==no){
		return no;
	}
	par[no]=find(par[no]);
	return par[no];
}
llo rec[1000001];
llo calc(int no){
	return rec[ss[no]];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,q;
	cin>>n>>q;

	for(int i=0;i<n;i++){
		par[i]=i;
		ss[i]=0;
	}
	llo su=0;
	for(llo i=0;i<n+1;i++){
		rec[i]=su;
		su+=(i+1);
	}
	pair<int,int> tt[n];
	int aa;

	for(int i=0;i<n;i++){
		cin>>aa;
		tt[i]={aa,i};
	}
	llo ans2[q];
	pair<int,int> it[q];
	for(int i=0;i<q;i++){
		cin>>aa;

		it[i]={aa,i};
	}
	sort(tt,tt+n);
	sort(it,it+q);

	int ind=0;
	llo ans=0;

	for(int k=0;k<q;k++){
		pair<int,int> nn=it[k];

		while(ind<n){
			if(tt[ind].a<=nn.a){
				ss[tt[ind].b]=1;
				ans+=calc(tt[ind].b);
				if(tt[ind].b>0){
					if(ss[tt[ind].b-1]>0){
						int x=find(tt[ind].b-1);
						ans-=calc(x);
						ans-=calc(tt[ind].b);
						ss[x]+=ss[tt[ind].b];
						par[tt[ind].b]=x;
						ans+=calc(x);
					}
					
				}
				if(tt[ind].b<n-1){
					if(ss[tt[ind].b+1]>0){
						int y=find(tt[ind].b);
						int x=find(tt[ind].b+1);
						if(ss[x]>ss[y]){
							ans-=calc(x);
							ans-=calc(y);
							ss[x]+=ss[y];
							par[y]=x;
							ans+=calc(x);
						}
						else{
							ans-=calc(x);
							ans-=calc(y);
							ss[y]+=ss[x];
							par[x]=y;
							ans+=calc(y);
						}

					}
				}
				ind+=1;
			}
			else{
				break;
			}
		}
	//	cout<<nn.b<<" "<<ans<<endl;
		ans2[nn.b]=ans;
	}
	for(int i=0;i<q;i++){
		cout<<ans2[i]<<endl;
	}




	return 0;
}
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 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 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 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 5 ms 512 KB Output is correct
15 Correct 5 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 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 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 5 ms 512 KB Output is correct
15 Correct 5 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 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 7 ms 384 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3200 KB Output is correct
2 Correct 28 ms 3328 KB Output is correct
3 Correct 28 ms 3072 KB Output is correct
4 Correct 27 ms 3124 KB Output is correct
5 Correct 27 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 6264 KB Output is correct
2 Correct 226 ms 6136 KB Output is correct
3 Correct 214 ms 6136 KB Output is correct
4 Correct 224 ms 6300 KB Output is correct
5 Correct 222 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 6264 KB Output is correct
2 Correct 213 ms 6264 KB Output is correct
3 Correct 236 ms 6264 KB Output is correct
4 Correct 221 ms 6408 KB Output is correct
5 Correct 230 ms 6520 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 28 ms 3200 KB Output is correct
12 Correct 28 ms 3328 KB Output is correct
13 Correct 28 ms 3072 KB Output is correct
14 Correct 27 ms 3124 KB Output is correct
15 Correct 27 ms 3072 KB Output is correct
16 Correct 26 ms 3072 KB Output is correct
17 Correct 26 ms 3328 KB Output is correct
18 Correct 28 ms 3328 KB Output is correct
19 Correct 24 ms 3072 KB Output is correct
20 Correct 27 ms 3200 KB Output is correct
21 Correct 29 ms 3072 KB Output is correct
22 Correct 26 ms 3200 KB Output is correct
23 Correct 27 ms 3200 KB Output is correct
24 Correct 25 ms 3200 KB Output is correct
25 Correct 27 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 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 5 ms 512 KB Output is correct
15 Correct 5 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 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 7 ms 384 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 7 ms 384 KB Output is correct
26 Correct 28 ms 3200 KB Output is correct
27 Correct 28 ms 3328 KB Output is correct
28 Correct 28 ms 3072 KB Output is correct
29 Correct 27 ms 3124 KB Output is correct
30 Correct 27 ms 3072 KB Output is correct
31 Correct 227 ms 6264 KB Output is correct
32 Correct 226 ms 6136 KB Output is correct
33 Correct 214 ms 6136 KB Output is correct
34 Correct 224 ms 6300 KB Output is correct
35 Correct 222 ms 6008 KB Output is correct
36 Correct 227 ms 6264 KB Output is correct
37 Correct 213 ms 6264 KB Output is correct
38 Correct 236 ms 6264 KB Output is correct
39 Correct 221 ms 6408 KB Output is correct
40 Correct 230 ms 6520 KB Output is correct
41 Correct 26 ms 3072 KB Output is correct
42 Correct 26 ms 3328 KB Output is correct
43 Correct 28 ms 3328 KB Output is correct
44 Correct 24 ms 3072 KB Output is correct
45 Correct 27 ms 3200 KB Output is correct
46 Correct 29 ms 3072 KB Output is correct
47 Correct 26 ms 3200 KB Output is correct
48 Correct 27 ms 3200 KB Output is correct
49 Correct 25 ms 3200 KB Output is correct
50 Correct 27 ms 3200 KB Output is correct
51 Correct 244 ms 6112 KB Output is correct
52 Correct 241 ms 6012 KB Output is correct
53 Correct 236 ms 6264 KB Output is correct
54 Correct 239 ms 6008 KB Output is correct
55 Correct 226 ms 6012 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 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 5 ms 512 KB Output is correct
15 Correct 5 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 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 7 ms 384 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 7 ms 384 KB Output is correct
26 Correct 28 ms 3200 KB Output is correct
27 Correct 28 ms 3328 KB Output is correct
28 Correct 28 ms 3072 KB Output is correct
29 Correct 27 ms 3124 KB Output is correct
30 Correct 27 ms 3072 KB Output is correct
31 Correct 227 ms 6264 KB Output is correct
32 Correct 226 ms 6136 KB Output is correct
33 Correct 214 ms 6136 KB Output is correct
34 Correct 224 ms 6300 KB Output is correct
35 Correct 222 ms 6008 KB Output is correct
36 Correct 227 ms 6264 KB Output is correct
37 Correct 213 ms 6264 KB Output is correct
38 Correct 236 ms 6264 KB Output is correct
39 Correct 221 ms 6408 KB Output is correct
40 Correct 230 ms 6520 KB Output is correct
41 Correct 26 ms 3072 KB Output is correct
42 Correct 26 ms 3328 KB Output is correct
43 Correct 28 ms 3328 KB Output is correct
44 Correct 24 ms 3072 KB Output is correct
45 Correct 27 ms 3200 KB Output is correct
46 Correct 29 ms 3072 KB Output is correct
47 Correct 26 ms 3200 KB Output is correct
48 Correct 27 ms 3200 KB Output is correct
49 Correct 25 ms 3200 KB Output is correct
50 Correct 27 ms 3200 KB Output is correct
51 Correct 244 ms 6112 KB Output is correct
52 Correct 241 ms 6012 KB Output is correct
53 Correct 236 ms 6264 KB Output is correct
54 Correct 239 ms 6008 KB Output is correct
55 Correct 226 ms 6012 KB Output is correct
56 Execution timed out 1096 ms 51824 KB Time limit exceeded
57 Halted 0 ms 0 KB -