답안 #369267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369267 2021-02-21T05:23:56 Z Berted Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 31876 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 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2412 KB Output is correct
2 Correct 22 ms 2540 KB Output is correct
3 Correct 22 ms 2412 KB Output is correct
4 Correct 21 ms 2412 KB Output is correct
5 Correct 22 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 5484 KB Output is correct
2 Correct 45 ms 5484 KB Output is correct
3 Correct 44 ms 5484 KB Output is correct
4 Correct 44 ms 5484 KB Output is correct
5 Correct 42 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 5504 KB Output is correct
2 Correct 44 ms 5484 KB Output is correct
3 Correct 43 ms 5612 KB Output is correct
4 Correct 43 ms 5612 KB Output is correct
5 Correct 45 ms 5740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
11 Correct 26 ms 2412 KB Output is correct
12 Correct 22 ms 2540 KB Output is correct
13 Correct 22 ms 2412 KB Output is correct
14 Correct 21 ms 2412 KB Output is correct
15 Correct 22 ms 2412 KB Output is correct
16 Correct 21 ms 2412 KB Output is correct
17 Correct 20 ms 2592 KB Output is correct
18 Correct 23 ms 2668 KB Output is correct
19 Correct 18 ms 2284 KB Output is correct
20 Correct 20 ms 2540 KB Output is correct
21 Correct 23 ms 2284 KB Output is correct
22 Correct 25 ms 2412 KB Output is correct
23 Correct 20 ms 2540 KB Output is correct
24 Correct 18 ms 2412 KB Output is correct
25 Correct 27 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 26 ms 2412 KB Output is correct
27 Correct 22 ms 2540 KB Output is correct
28 Correct 22 ms 2412 KB Output is correct
29 Correct 21 ms 2412 KB Output is correct
30 Correct 22 ms 2412 KB Output is correct
31 Correct 47 ms 5484 KB Output is correct
32 Correct 45 ms 5484 KB Output is correct
33 Correct 44 ms 5484 KB Output is correct
34 Correct 44 ms 5484 KB Output is correct
35 Correct 42 ms 5484 KB Output is correct
36 Correct 43 ms 5504 KB Output is correct
37 Correct 44 ms 5484 KB Output is correct
38 Correct 43 ms 5612 KB Output is correct
39 Correct 43 ms 5612 KB Output is correct
40 Correct 45 ms 5740 KB Output is correct
41 Correct 21 ms 2412 KB Output is correct
42 Correct 20 ms 2592 KB Output is correct
43 Correct 23 ms 2668 KB Output is correct
44 Correct 18 ms 2284 KB Output is correct
45 Correct 20 ms 2540 KB Output is correct
46 Correct 23 ms 2284 KB Output is correct
47 Correct 25 ms 2412 KB Output is correct
48 Correct 20 ms 2540 KB Output is correct
49 Correct 18 ms 2412 KB Output is correct
50 Correct 27 ms 2412 KB Output is correct
51 Correct 59 ms 5356 KB Output is correct
52 Correct 52 ms 5356 KB Output is correct
53 Correct 55 ms 5356 KB Output is correct
54 Correct 53 ms 5228 KB Output is correct
55 Correct 52 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 1 ms 364 KB Output is correct
6 Correct 1 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 26 ms 2412 KB Output is correct
27 Correct 22 ms 2540 KB Output is correct
28 Correct 22 ms 2412 KB Output is correct
29 Correct 21 ms 2412 KB Output is correct
30 Correct 22 ms 2412 KB Output is correct
31 Correct 47 ms 5484 KB Output is correct
32 Correct 45 ms 5484 KB Output is correct
33 Correct 44 ms 5484 KB Output is correct
34 Correct 44 ms 5484 KB Output is correct
35 Correct 42 ms 5484 KB Output is correct
36 Correct 43 ms 5504 KB Output is correct
37 Correct 44 ms 5484 KB Output is correct
38 Correct 43 ms 5612 KB Output is correct
39 Correct 43 ms 5612 KB Output is correct
40 Correct 45 ms 5740 KB Output is correct
41 Correct 21 ms 2412 KB Output is correct
42 Correct 20 ms 2592 KB Output is correct
43 Correct 23 ms 2668 KB Output is correct
44 Correct 18 ms 2284 KB Output is correct
45 Correct 20 ms 2540 KB Output is correct
46 Correct 23 ms 2284 KB Output is correct
47 Correct 25 ms 2412 KB Output is correct
48 Correct 20 ms 2540 KB Output is correct
49 Correct 18 ms 2412 KB Output is correct
50 Correct 27 ms 2412 KB Output is correct
51 Correct 59 ms 5356 KB Output is correct
52 Correct 52 ms 5356 KB Output is correct
53 Correct 55 ms 5356 KB Output is correct
54 Correct 53 ms 5228 KB Output is correct
55 Correct 52 ms 5484 KB Output is correct
56 Execution timed out 1135 ms 31876 KB Time limit exceeded
57 Halted 0 ms 0 KB -