답안 #239807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239807 2020-06-17T10:27:06 Z arnold518 Pilot (NOI19_pilot) C++14
100 / 100
854 ms 57296 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6;

int N, Q, A[MAXN+10];
pii B[MAXN+10];

int par[MAXN+10], sz[MAXN+10];
bool vis[MAXN+10];
ll ans[MAXN+10];

int Find(int x)
{
	if(x==par[x]) return x;
	return par[x]=Find(par[x]);
}

ll val=0;

void Union(int x, int y)
{
	x=Find(x); y=Find(y);
	if(x==y) return;
	val-=(ll)sz[x]*(sz[x]+1)/2;
	val-=(ll)sz[y]*(sz[y]+1)/2;
	sz[x]+=sz[y]; par[y]=x;
	val+=(ll)sz[x]*(sz[x]+1)/2;
}

int main()
{
	int i, j;

	scanf("%d%d", &N, &Q);
	for(i=1; i<=N; i++) par[i]=i, sz[i]=1;
	for(i=1; i<=N; i++) scanf("%d", &A[i]);
	for(i=1; i<=Q; i++) scanf("%d", &B[i].first), B[i].second=i;
	sort(B+1, B+Q+1);
	
	vector<pii> V;
	for(i=1; i<=N; i++) V.push_back({A[i], i});
	sort(V.begin(), V.end());	

	for(i=1, j=0; i<=Q; i++)
	{
		for(; j<V.size() && V[j].first<=B[i].first; j++)
		{
			int now=V[j].second;

			vis[now]=true; val++;
			if(now!=1 && vis[now-1]) Union(now, now-1);
			if(now!=N && vis[now+1]) Union(now, now+1);
		}
		ans[B[i].second]=val;
	}
	for(i=1; i<=Q; i++) printf("%lld\n", ans[i]);
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:51:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(; j<V.size() && V[j].first<=B[i].first; j++)
         ~^~~~~~~~~
pilot.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
pilot.cpp:41:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N; i++) scanf("%d", &A[i]);
                      ~~~~~^~~~~~~~~~~~~
pilot.cpp:42:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=Q; i++) scanf("%d", &B[i].first), B[i].second=i;
                      ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 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 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 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 5 ms 384 KB Output is correct
15 Correct 5 ms 384 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 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 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 5 ms 384 KB Output is correct
15 Correct 5 ms 384 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 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2808 KB Output is correct
2 Correct 35 ms 2800 KB Output is correct
3 Correct 35 ms 2680 KB Output is correct
4 Correct 32 ms 2680 KB Output is correct
5 Correct 33 ms 2672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 4972 KB Output is correct
2 Correct 57 ms 5228 KB Output is correct
3 Correct 57 ms 4972 KB Output is correct
4 Correct 59 ms 5100 KB Output is correct
5 Correct 57 ms 4976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 4972 KB Output is correct
2 Correct 57 ms 4972 KB Output is correct
3 Correct 60 ms 4972 KB Output is correct
4 Correct 59 ms 4972 KB Output is correct
5 Correct 72 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 34 ms 2808 KB Output is correct
12 Correct 35 ms 2800 KB Output is correct
13 Correct 35 ms 2680 KB Output is correct
14 Correct 32 ms 2680 KB Output is correct
15 Correct 33 ms 2672 KB Output is correct
16 Correct 31 ms 2680 KB Output is correct
17 Correct 31 ms 2800 KB Output is correct
18 Correct 32 ms 2808 KB Output is correct
19 Correct 28 ms 2808 KB Output is correct
20 Correct 32 ms 2808 KB Output is correct
21 Correct 33 ms 2680 KB Output is correct
22 Correct 33 ms 2680 KB Output is correct
23 Correct 31 ms 2808 KB Output is correct
24 Correct 29 ms 2680 KB Output is correct
25 Correct 31 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 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 5 ms 384 KB Output is correct
15 Correct 5 ms 384 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 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 34 ms 2808 KB Output is correct
27 Correct 35 ms 2800 KB Output is correct
28 Correct 35 ms 2680 KB Output is correct
29 Correct 32 ms 2680 KB Output is correct
30 Correct 33 ms 2672 KB Output is correct
31 Correct 57 ms 4972 KB Output is correct
32 Correct 57 ms 5228 KB Output is correct
33 Correct 57 ms 4972 KB Output is correct
34 Correct 59 ms 5100 KB Output is correct
35 Correct 57 ms 4976 KB Output is correct
36 Correct 59 ms 4972 KB Output is correct
37 Correct 57 ms 4972 KB Output is correct
38 Correct 60 ms 4972 KB Output is correct
39 Correct 59 ms 4972 KB Output is correct
40 Correct 72 ms 5100 KB Output is correct
41 Correct 31 ms 2680 KB Output is correct
42 Correct 31 ms 2800 KB Output is correct
43 Correct 32 ms 2808 KB Output is correct
44 Correct 28 ms 2808 KB Output is correct
45 Correct 32 ms 2808 KB Output is correct
46 Correct 33 ms 2680 KB Output is correct
47 Correct 33 ms 2680 KB Output is correct
48 Correct 31 ms 2808 KB Output is correct
49 Correct 29 ms 2680 KB Output is correct
50 Correct 31 ms 2808 KB Output is correct
51 Correct 72 ms 4972 KB Output is correct
52 Correct 71 ms 4716 KB Output is correct
53 Correct 70 ms 4968 KB Output is correct
54 Correct 79 ms 4716 KB Output is correct
55 Correct 73 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 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 5 ms 384 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 5 ms 384 KB Output is correct
15 Correct 5 ms 384 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 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 34 ms 2808 KB Output is correct
27 Correct 35 ms 2800 KB Output is correct
28 Correct 35 ms 2680 KB Output is correct
29 Correct 32 ms 2680 KB Output is correct
30 Correct 33 ms 2672 KB Output is correct
31 Correct 57 ms 4972 KB Output is correct
32 Correct 57 ms 5228 KB Output is correct
33 Correct 57 ms 4972 KB Output is correct
34 Correct 59 ms 5100 KB Output is correct
35 Correct 57 ms 4976 KB Output is correct
36 Correct 59 ms 4972 KB Output is correct
37 Correct 57 ms 4972 KB Output is correct
38 Correct 60 ms 4972 KB Output is correct
39 Correct 59 ms 4972 KB Output is correct
40 Correct 72 ms 5100 KB Output is correct
41 Correct 31 ms 2680 KB Output is correct
42 Correct 31 ms 2800 KB Output is correct
43 Correct 32 ms 2808 KB Output is correct
44 Correct 28 ms 2808 KB Output is correct
45 Correct 32 ms 2808 KB Output is correct
46 Correct 33 ms 2680 KB Output is correct
47 Correct 33 ms 2680 KB Output is correct
48 Correct 31 ms 2808 KB Output is correct
49 Correct 29 ms 2680 KB Output is correct
50 Correct 31 ms 2808 KB Output is correct
51 Correct 72 ms 4972 KB Output is correct
52 Correct 71 ms 4716 KB Output is correct
53 Correct 70 ms 4968 KB Output is correct
54 Correct 79 ms 4716 KB Output is correct
55 Correct 73 ms 4972 KB Output is correct
56 Correct 813 ms 48336 KB Output is correct
57 Correct 819 ms 55440 KB Output is correct
58 Correct 790 ms 52560 KB Output is correct
59 Correct 854 ms 53664 KB Output is correct
60 Correct 854 ms 57296 KB Output is correct