Submission #956725

# Submission time Handle Problem Language Result Execution time Memory
956725 2024-04-02T11:40:13 Z MilosMilutinovic Pilot (NOI19_pilot) C++14
100 / 100
386 ms 56608 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,q;
int a[1000005],sz[1000005],fa[1000005];
vector<pii> qry;
ll res[1000005],cur;

ll f(ll x){return x*(x+1)/2;}

int getf(int x){return fa[x]==x?x:fa[x]=getf(fa[x]);}

void unite(int x,int y){
	x=getf(x);
	y=getf(y);
	if(x==y) return;
	cur-=f(sz[x]);
	cur-=f(sz[y]);
	sz[x]+=sz[y];
	cur+=f(sz[x]);
	fa[y]=x;
}
int main(){
	n=readint(); q=readint();
	int x;
	for(int i=1;i<=n;i++){
		x=readint();
		qry.pb(mp(x,-i));
	}
	for(int i=1;i<=q;i++){
		x=readint();
		qry.pb(mp(x,i));
	}
	sort(qry.begin(),qry.end());
	for(auto p:qry){
		int idx=p.se;
		if(idx<0){
			idx=-idx;
			sz[idx]=1;
			fa[idx]=idx;
			cur+=1;
			if(a[idx-1]==1) unite(idx,idx-1);
			if(a[idx+1]==1) unite(idx,idx+1);
			a[idx]=1;
		}else{
			res[idx]=cur;
		}
	}
	for(int i=1;i<=q;i++) printf("%lld\n",res[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4544 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4544 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4544 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4548 KB Output is correct
24 Correct 2 ms 4532 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6352 KB Output is correct
2 Correct 14 ms 6480 KB Output is correct
3 Correct 13 ms 6096 KB Output is correct
4 Correct 12 ms 6252 KB Output is correct
5 Correct 13 ms 6096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 10808 KB Output is correct
2 Correct 28 ms 10952 KB Output is correct
3 Correct 28 ms 10852 KB Output is correct
4 Correct 29 ms 11140 KB Output is correct
5 Correct 27 ms 10700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 10688 KB Output is correct
2 Correct 28 ms 10924 KB Output is correct
3 Correct 28 ms 10944 KB Output is correct
4 Correct 28 ms 10944 KB Output is correct
5 Correct 29 ms 10940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 13 ms 6352 KB Output is correct
12 Correct 14 ms 6480 KB Output is correct
13 Correct 13 ms 6096 KB Output is correct
14 Correct 12 ms 6252 KB Output is correct
15 Correct 13 ms 6096 KB Output is correct
16 Correct 13 ms 6096 KB Output is correct
17 Correct 13 ms 6348 KB Output is correct
18 Correct 13 ms 6352 KB Output is correct
19 Correct 12 ms 6096 KB Output is correct
20 Correct 13 ms 6336 KB Output is correct
21 Correct 13 ms 6096 KB Output is correct
22 Correct 12 ms 6352 KB Output is correct
23 Correct 13 ms 6352 KB Output is correct
24 Correct 12 ms 6352 KB Output is correct
25 Correct 13 ms 6348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4544 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4548 KB Output is correct
24 Correct 2 ms 4532 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 13 ms 6352 KB Output is correct
27 Correct 14 ms 6480 KB Output is correct
28 Correct 13 ms 6096 KB Output is correct
29 Correct 12 ms 6252 KB Output is correct
30 Correct 13 ms 6096 KB Output is correct
31 Correct 28 ms 10808 KB Output is correct
32 Correct 28 ms 10952 KB Output is correct
33 Correct 28 ms 10852 KB Output is correct
34 Correct 29 ms 11140 KB Output is correct
35 Correct 27 ms 10700 KB Output is correct
36 Correct 27 ms 10688 KB Output is correct
37 Correct 28 ms 10924 KB Output is correct
38 Correct 28 ms 10944 KB Output is correct
39 Correct 28 ms 10944 KB Output is correct
40 Correct 29 ms 10940 KB Output is correct
41 Correct 13 ms 6096 KB Output is correct
42 Correct 13 ms 6348 KB Output is correct
43 Correct 13 ms 6352 KB Output is correct
44 Correct 12 ms 6096 KB Output is correct
45 Correct 13 ms 6336 KB Output is correct
46 Correct 13 ms 6096 KB Output is correct
47 Correct 12 ms 6352 KB Output is correct
48 Correct 13 ms 6352 KB Output is correct
49 Correct 12 ms 6352 KB Output is correct
50 Correct 13 ms 6348 KB Output is correct
51 Correct 32 ms 10680 KB Output is correct
52 Correct 32 ms 10576 KB Output is correct
53 Correct 32 ms 10692 KB Output is correct
54 Correct 37 ms 10436 KB Output is correct
55 Correct 32 ms 10684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4544 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4548 KB Output is correct
24 Correct 2 ms 4532 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 13 ms 6352 KB Output is correct
27 Correct 14 ms 6480 KB Output is correct
28 Correct 13 ms 6096 KB Output is correct
29 Correct 12 ms 6252 KB Output is correct
30 Correct 13 ms 6096 KB Output is correct
31 Correct 28 ms 10808 KB Output is correct
32 Correct 28 ms 10952 KB Output is correct
33 Correct 28 ms 10852 KB Output is correct
34 Correct 29 ms 11140 KB Output is correct
35 Correct 27 ms 10700 KB Output is correct
36 Correct 27 ms 10688 KB Output is correct
37 Correct 28 ms 10924 KB Output is correct
38 Correct 28 ms 10944 KB Output is correct
39 Correct 28 ms 10944 KB Output is correct
40 Correct 29 ms 10940 KB Output is correct
41 Correct 13 ms 6096 KB Output is correct
42 Correct 13 ms 6348 KB Output is correct
43 Correct 13 ms 6352 KB Output is correct
44 Correct 12 ms 6096 KB Output is correct
45 Correct 13 ms 6336 KB Output is correct
46 Correct 13 ms 6096 KB Output is correct
47 Correct 12 ms 6352 KB Output is correct
48 Correct 13 ms 6352 KB Output is correct
49 Correct 12 ms 6352 KB Output is correct
50 Correct 13 ms 6348 KB Output is correct
51 Correct 32 ms 10680 KB Output is correct
52 Correct 32 ms 10576 KB Output is correct
53 Correct 32 ms 10692 KB Output is correct
54 Correct 37 ms 10436 KB Output is correct
55 Correct 32 ms 10684 KB Output is correct
56 Correct 367 ms 55328 KB Output is correct
57 Correct 364 ms 54936 KB Output is correct
58 Correct 349 ms 54128 KB Output is correct
59 Correct 386 ms 54000 KB Output is correct
60 Correct 385 ms 56608 KB Output is correct