Submission #224508

# Submission time Handle Problem Language Result Execution time Memory
224508 2020-04-18T09:21:30 Z kshitij_sodani Pilot (NOI19_pilot) C++17
89 / 100
253 ms 8292 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long int llo;
llo mod=1000000007;
llo par[100001];
llo ss[100001];
llo find(llo no){
	if(par[no]==no){
		return no;
	}
	par[no]=find(par[no]);
	return par[no];
}
llo calc(llo no){
	return (ss[no]*(ss[no]+1))/2;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n,q;
	cin>>n>>q;
	for(llo i=0;i<n;i++){
		par[i]=i;
		ss[i]=0;
	}
	vector<pair<llo,llo>> tt;
	llo aa;
	for(llo i=0;i<n;i++){
		cin>>aa;
		tt.pb({aa,i});
	}
	llo ans2[q];
	vector<pair<llo,llo>> it;
	for(llo i=0;i<q;i++){
		cin>>aa;
		it.pb({aa,i});
	}
	sort(tt.begin(),tt.end());
	sort(it.begin(),it.end());
	llo ind=0;
	llo ans=0;
	for(auto nn:it){
		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){
						llo x=find(tt[ind].b-1);
						ans-=calc(x);
						ans-=calc(tt[ind].b);
						ss[tt[ind].b]+=ss[x];
						par[x]=tt[ind].b;
						ans+=calc(tt[ind].b);
					}
					
				}
				if(tt[ind].b<n-1){
					if(ss[tt[ind].b+1]>0){
						llo x=find(tt[ind].b+1);
						ans-=calc(x);
						ans-=calc(tt[ind].b);
						ss[tt[ind].b]+=ss[x];
						par[x]=tt[ind].b;
						ans+=calc(tt[ind].b);
					}
				}
				ind+=1;
			}
			else{
				break;
			}
		}
	//	cout<<nn.b<<" "<<ans<<endl;
		ans2[nn.b]=ans;
	}
	for(llo i=0;i<q;i++){
		cout<<ans2[i]<<endl;
	}




	return 0;
}
# 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 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 5 ms 256 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 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 5 ms 256 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 6 ms 384 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 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 5 ms 256 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 6 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 4600 KB Output is correct
2 Correct 32 ms 4728 KB Output is correct
3 Correct 30 ms 4600 KB Output is correct
4 Correct 30 ms 4652 KB Output is correct
5 Correct 35 ms 4616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 7652 KB Output is correct
2 Correct 235 ms 7780 KB Output is correct
3 Correct 235 ms 7788 KB Output is correct
4 Correct 235 ms 7956 KB Output is correct
5 Correct 227 ms 7652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 7780 KB Output is correct
2 Correct 223 ms 7932 KB Output is correct
3 Correct 229 ms 8036 KB Output is correct
4 Correct 226 ms 8032 KB Output is correct
5 Correct 234 ms 8292 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 32 ms 4600 KB Output is correct
12 Correct 32 ms 4728 KB Output is correct
13 Correct 30 ms 4600 KB Output is correct
14 Correct 30 ms 4652 KB Output is correct
15 Correct 35 ms 4616 KB Output is correct
16 Correct 27 ms 4600 KB Output is correct
17 Correct 28 ms 4728 KB Output is correct
18 Correct 28 ms 4728 KB Output is correct
19 Correct 27 ms 4472 KB Output is correct
20 Correct 29 ms 4600 KB Output is correct
21 Correct 30 ms 4472 KB Output is correct
22 Correct 27 ms 4592 KB Output is correct
23 Correct 29 ms 4600 KB Output is correct
24 Correct 26 ms 4600 KB Output is correct
25 Correct 28 ms 4600 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 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 5 ms 256 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 6 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 32 ms 4600 KB Output is correct
27 Correct 32 ms 4728 KB Output is correct
28 Correct 30 ms 4600 KB Output is correct
29 Correct 30 ms 4652 KB Output is correct
30 Correct 35 ms 4616 KB Output is correct
31 Correct 223 ms 7652 KB Output is correct
32 Correct 235 ms 7780 KB Output is correct
33 Correct 235 ms 7788 KB Output is correct
34 Correct 235 ms 7956 KB Output is correct
35 Correct 227 ms 7652 KB Output is correct
36 Correct 216 ms 7780 KB Output is correct
37 Correct 223 ms 7932 KB Output is correct
38 Correct 229 ms 8036 KB Output is correct
39 Correct 226 ms 8032 KB Output is correct
40 Correct 234 ms 8292 KB Output is correct
41 Correct 27 ms 4600 KB Output is correct
42 Correct 28 ms 4728 KB Output is correct
43 Correct 28 ms 4728 KB Output is correct
44 Correct 27 ms 4472 KB Output is correct
45 Correct 29 ms 4600 KB Output is correct
46 Correct 30 ms 4472 KB Output is correct
47 Correct 27 ms 4592 KB Output is correct
48 Correct 29 ms 4600 KB Output is correct
49 Correct 26 ms 4600 KB Output is correct
50 Correct 28 ms 4600 KB Output is correct
51 Correct 236 ms 7908 KB Output is correct
52 Correct 253 ms 7660 KB Output is correct
53 Correct 241 ms 7780 KB Output is correct
54 Correct 243 ms 7780 KB Output is correct
55 Correct 239 ms 7780 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 4 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 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 5 ms 256 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 6 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 32 ms 4600 KB Output is correct
27 Correct 32 ms 4728 KB Output is correct
28 Correct 30 ms 4600 KB Output is correct
29 Correct 30 ms 4652 KB Output is correct
30 Correct 35 ms 4616 KB Output is correct
31 Correct 223 ms 7652 KB Output is correct
32 Correct 235 ms 7780 KB Output is correct
33 Correct 235 ms 7788 KB Output is correct
34 Correct 235 ms 7956 KB Output is correct
35 Correct 227 ms 7652 KB Output is correct
36 Correct 216 ms 7780 KB Output is correct
37 Correct 223 ms 7932 KB Output is correct
38 Correct 229 ms 8036 KB Output is correct
39 Correct 226 ms 8032 KB Output is correct
40 Correct 234 ms 8292 KB Output is correct
41 Correct 27 ms 4600 KB Output is correct
42 Correct 28 ms 4728 KB Output is correct
43 Correct 28 ms 4728 KB Output is correct
44 Correct 27 ms 4472 KB Output is correct
45 Correct 29 ms 4600 KB Output is correct
46 Correct 30 ms 4472 KB Output is correct
47 Correct 27 ms 4592 KB Output is correct
48 Correct 29 ms 4600 KB Output is correct
49 Correct 26 ms 4600 KB Output is correct
50 Correct 28 ms 4600 KB Output is correct
51 Correct 236 ms 7908 KB Output is correct
52 Correct 253 ms 7660 KB Output is correct
53 Correct 241 ms 7780 KB Output is correct
54 Correct 243 ms 7780 KB Output is correct
55 Correct 239 ms 7780 KB Output is correct
56 Runtime error 7 ms 3712 KB Execution killed with signal 11 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -