Submission #369274

# Submission time Handle Problem Language Result Execution time Memory
369274 2021-02-21T05:27:35 Z Berted Pilot (NOI19_pilot) C++11
100 / 100
669 ms 42080 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;
}
# Verdict Execution time Memory 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 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
# Verdict Execution time Memory 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 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
# Verdict Execution time Memory 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 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 384 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
# Verdict Execution time Memory 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 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 384 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 492 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 620 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2412 KB Output is correct
2 Correct 23 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 21 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 5356 KB Output is correct
2 Correct 45 ms 5484 KB Output is correct
3 Correct 43 ms 5484 KB Output is correct
4 Correct 43 ms 5484 KB Output is correct
5 Correct 44 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5612 KB Output is correct
2 Correct 44 ms 5636 KB Output is correct
3 Correct 44 ms 5612 KB Output is correct
4 Correct 43 ms 5612 KB Output is correct
5 Correct 45 ms 5740 KB Output is correct
# Verdict Execution time Memory 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 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 22 ms 2412 KB Output is correct
12 Correct 23 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 21 ms 2412 KB Output is correct
16 Correct 20 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 19 ms 2284 KB Output is correct
20 Correct 25 ms 2540 KB Output is correct
21 Correct 21 ms 2284 KB Output is correct
22 Correct 20 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 20 ms 2412 KB Output is correct
# Verdict Execution time Memory 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 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 384 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 492 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 620 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 22 ms 2412 KB Output is correct
27 Correct 23 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 21 ms 2412 KB Output is correct
31 Correct 41 ms 5356 KB Output is correct
32 Correct 45 ms 5484 KB Output is correct
33 Correct 43 ms 5484 KB Output is correct
34 Correct 43 ms 5484 KB Output is correct
35 Correct 44 ms 5356 KB Output is correct
36 Correct 44 ms 5612 KB Output is correct
37 Correct 44 ms 5636 KB Output is correct
38 Correct 44 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 20 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 19 ms 2284 KB Output is correct
45 Correct 25 ms 2540 KB Output is correct
46 Correct 21 ms 2284 KB Output is correct
47 Correct 20 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 20 ms 2412 KB Output is correct
51 Correct 53 ms 5356 KB Output is correct
52 Correct 51 ms 5484 KB Output is correct
53 Correct 52 ms 5356 KB Output is correct
54 Correct 51 ms 5228 KB Output is correct
55 Correct 53 ms 5356 KB Output is correct
# Verdict Execution time Memory 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 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 384 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 492 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 620 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 22 ms 2412 KB Output is correct
27 Correct 23 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 21 ms 2412 KB Output is correct
31 Correct 41 ms 5356 KB Output is correct
32 Correct 45 ms 5484 KB Output is correct
33 Correct 43 ms 5484 KB Output is correct
34 Correct 43 ms 5484 KB Output is correct
35 Correct 44 ms 5356 KB Output is correct
36 Correct 44 ms 5612 KB Output is correct
37 Correct 44 ms 5636 KB Output is correct
38 Correct 44 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 20 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 19 ms 2284 KB Output is correct
45 Correct 25 ms 2540 KB Output is correct
46 Correct 21 ms 2284 KB Output is correct
47 Correct 20 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 20 ms 2412 KB Output is correct
51 Correct 53 ms 5356 KB Output is correct
52 Correct 51 ms 5484 KB Output is correct
53 Correct 52 ms 5356 KB Output is correct
54 Correct 51 ms 5228 KB Output is correct
55 Correct 53 ms 5356 KB Output is correct
56 Correct 621 ms 41236 KB Output is correct
57 Correct 605 ms 40556 KB Output is correct
58 Correct 577 ms 38892 KB Output is correct
59 Correct 580 ms 39532 KB Output is correct
60 Correct 669 ms 42080 KB Output is correct