답안 #369273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369273 2021-02-21T05:27:02 Z Berted Pilot (NOI19_pilot) C++14
100 / 100
632 ms 52204 KB
#include <iostream>
#include <algorithm>
#define pii pair<int,int>
#define fst first
#define snd second
#define ll long long
using namespace std;
int n,q;pii ar[1000001]={},qry[1000001]={};
int prt[1000001]={},sz[1000001]={};
ll to = 0,rs[1000001]={};
int fn(int x) {return prt[x] = (prt[x] - x)?fn(prt[x]):x;}
void jn(int a,int b)
{
	a = fn(a), b = fn(b);
	if (a!=b)
	{
		if (sz[a]<sz[b]) {swap(a,b);}
		prt[b] = a;
		to -= (ll)sz[b]*(sz[b]+1)/2;
		to -= (ll)sz[a]*(sz[a]+1)/2;
		sz[a] += sz[b];sz[b] = 0;
		to += (ll)sz[a]*(sz[a]+1)/2;
	}
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for (int i=0;i<n;i++) {cin>>ar[i].fst;ar[i].snd = i;prt[i] = -1;}
	for (int i=0;i<q;i++) {cin>>qry[i].fst;qry[i].snd = i;}
	sort(ar,ar+n);sort(qry,qry+q);
	int j = 0;
	for (int i=0;i<q;i++)
	{
		for (;j<n;j++)
		{
			if (ar[j].fst<=qry[i].fst) 
			{
				prt[ar[j].snd] = ar[j].snd;
				sz[ar[j].snd] = 1;to++;
				if (ar[j].snd)
				{
					if (prt[ar[j].snd-1]!=-1)
					{
						jn(ar[j].snd,ar[j].snd-1);
					}
				}
				if (ar[j].snd<n-1)
				{
					if (prt[ar[j].snd+1]!=-1)
					{
						jn(ar[j].snd,ar[j].snd+1);
					}
				}
			}
			else {break;}
		}
		rs[qry[i].snd] = to;
	}
	for (int i=0;i<q;i++)
	{
		cout<<rs[i]<<"\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 68 ms 364 KB Output is correct
14 Correct 35 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 68 ms 364 KB Output is correct
14 Correct 35 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 68 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 68 ms 364 KB Output is correct
14 Correct 35 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 68 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 103 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 64 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2412 KB Output is correct
2 Correct 23 ms 2540 KB Output is correct
3 Correct 259 ms 2412 KB Output is correct
4 Correct 20 ms 2432 KB Output is correct
5 Correct 21 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 5320 KB Output is correct
2 Correct 43 ms 5484 KB Output is correct
3 Correct 44 ms 5484 KB Output is correct
4 Correct 43 ms 5484 KB Output is correct
5 Correct 51 ms 5428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 5484 KB Output is correct
2 Correct 44 ms 5524 KB Output is correct
3 Correct 44 ms 5612 KB Output is correct
4 Correct 42 ms 5612 KB Output is correct
5 Correct 51 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
11 Correct 23 ms 2412 KB Output is correct
12 Correct 23 ms 2540 KB Output is correct
13 Correct 259 ms 2412 KB Output is correct
14 Correct 20 ms 2432 KB Output is correct
15 Correct 21 ms 2412 KB Output is correct
16 Correct 22 ms 2412 KB Output is correct
17 Correct 19 ms 2540 KB Output is correct
18 Correct 20 ms 2540 KB Output is correct
19 Correct 21 ms 2284 KB Output is correct
20 Correct 20 ms 2540 KB Output is correct
21 Correct 21 ms 2284 KB Output is correct
22 Correct 19 ms 2412 KB Output is correct
23 Correct 20 ms 2540 KB Output is correct
24 Correct 20 ms 2412 KB Output is correct
25 Correct 20 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 68 ms 364 KB Output is correct
14 Correct 35 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 68 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 103 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 64 ms 492 KB Output is correct
26 Correct 23 ms 2412 KB Output is correct
27 Correct 23 ms 2540 KB Output is correct
28 Correct 259 ms 2412 KB Output is correct
29 Correct 20 ms 2432 KB Output is correct
30 Correct 21 ms 2412 KB Output is correct
31 Correct 41 ms 5320 KB Output is correct
32 Correct 43 ms 5484 KB Output is correct
33 Correct 44 ms 5484 KB Output is correct
34 Correct 43 ms 5484 KB Output is correct
35 Correct 51 ms 5428 KB Output is correct
36 Correct 42 ms 5484 KB Output is correct
37 Correct 44 ms 5524 KB Output is correct
38 Correct 44 ms 5612 KB Output is correct
39 Correct 42 ms 5612 KB Output is correct
40 Correct 51 ms 5868 KB Output is correct
41 Correct 22 ms 2412 KB Output is correct
42 Correct 19 ms 2540 KB Output is correct
43 Correct 20 ms 2540 KB Output is correct
44 Correct 21 ms 2284 KB Output is correct
45 Correct 20 ms 2540 KB Output is correct
46 Correct 21 ms 2284 KB Output is correct
47 Correct 19 ms 2412 KB Output is correct
48 Correct 20 ms 2540 KB Output is correct
49 Correct 20 ms 2412 KB Output is correct
50 Correct 20 ms 2412 KB Output is correct
51 Correct 53 ms 5356 KB Output is correct
52 Correct 62 ms 5356 KB Output is correct
53 Correct 52 ms 5356 KB Output is correct
54 Correct 51 ms 5228 KB Output is correct
55 Correct 54 ms 5356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 34 ms 364 KB Output is correct
6 Correct 34 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 67 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 68 ms 364 KB Output is correct
14 Correct 35 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 68 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 103 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 64 ms 492 KB Output is correct
26 Correct 23 ms 2412 KB Output is correct
27 Correct 23 ms 2540 KB Output is correct
28 Correct 259 ms 2412 KB Output is correct
29 Correct 20 ms 2432 KB Output is correct
30 Correct 21 ms 2412 KB Output is correct
31 Correct 41 ms 5320 KB Output is correct
32 Correct 43 ms 5484 KB Output is correct
33 Correct 44 ms 5484 KB Output is correct
34 Correct 43 ms 5484 KB Output is correct
35 Correct 51 ms 5428 KB Output is correct
36 Correct 42 ms 5484 KB Output is correct
37 Correct 44 ms 5524 KB Output is correct
38 Correct 44 ms 5612 KB Output is correct
39 Correct 42 ms 5612 KB Output is correct
40 Correct 51 ms 5868 KB Output is correct
41 Correct 22 ms 2412 KB Output is correct
42 Correct 19 ms 2540 KB Output is correct
43 Correct 20 ms 2540 KB Output is correct
44 Correct 21 ms 2284 KB Output is correct
45 Correct 20 ms 2540 KB Output is correct
46 Correct 21 ms 2284 KB Output is correct
47 Correct 19 ms 2412 KB Output is correct
48 Correct 20 ms 2540 KB Output is correct
49 Correct 20 ms 2412 KB Output is correct
50 Correct 20 ms 2412 KB Output is correct
51 Correct 53 ms 5356 KB Output is correct
52 Correct 62 ms 5356 KB Output is correct
53 Correct 52 ms 5356 KB Output is correct
54 Correct 51 ms 5228 KB Output is correct
55 Correct 54 ms 5356 KB Output is correct
56 Correct 617 ms 51360 KB Output is correct
57 Correct 619 ms 50564 KB Output is correct
58 Correct 574 ms 48080 KB Output is correct
59 Correct 591 ms 48928 KB Output is correct
60 Correct 632 ms 52204 KB Output is correct