답안 #321203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321203 2020-11-11T13:49:46 Z techiehere08 Pilot (NOI19_pilot) C++14
100 / 100
812 ms 41060 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 10;
int par[N], len[N], n, m,  j, i;
long long res[N], ans;
bool ok[N];
array < int, 2 > A[N], B[N];

long long foo(int x){
  return (1ll * x * (x + 1)) / 2;
}

int find(int u){
  if(u == par[u]){
    return u;
  }
  return par[u] = find(par[u]);
}

void join(int a, int b){
  if(!ok[a] || !ok[b]){
    return;
  }
  a = find(a), b = find(b);
  ans -= foo(len[a]);
  ans -= foo(len[b]);
  if(len[a] < len[b]) swap(a, b);
  len[a] += len[b];
  par[b] = par[a];
  ans += foo(len[a]);
}

void refresh(int v){
  ok[v] = true;
  ans += foo(len[v]);
  join(v, v + 1);
  join(v, v - 1);
}

int main(){
  scanf("%d%d", &n, &m);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i][0]);
    A[i][1] = i + 1;
    par[i] = i, len[i] = 1;
  }
  par[n] = n, len[n] = 1;
  for(i = 0; i < m; i++){
    scanf("%d", &B[i][0]);
    B[i][1] = i;
  }
  sort(A, A + n), sort(B, B + m);
  j = 0;
  for(i = 0; i < m; i++){
    while(j < n && A[j][0] <= B[i][0]){
      refresh(A[j][1]);
      j++;
    }
    res[B[i][1]] = ans;
  }
  for(i = 0; i < m; i++){
    printf("%lld\n", res[i]);
  }
  return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
pilot.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%d", &A[i][0]);
      |     ~~~~~^~~~~~~~~~~~~~~~
pilot.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |     scanf("%d", &B[i][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 1 ms 364 KB Output is correct
6 Correct 0 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 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 0 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 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 0 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 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 0 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 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2540 KB Output is correct
2 Correct 29 ms 2660 KB Output is correct
3 Correct 28 ms 2404 KB Output is correct
4 Correct 27 ms 2412 KB Output is correct
5 Correct 28 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 5092 KB Output is correct
2 Correct 57 ms 5092 KB Output is correct
3 Correct 56 ms 5092 KB Output is correct
4 Correct 57 ms 5092 KB Output is correct
5 Correct 56 ms 5092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 4964 KB Output is correct
2 Correct 59 ms 5092 KB Output is correct
3 Correct 60 ms 5092 KB Output is correct
4 Correct 57 ms 5092 KB Output is correct
5 Correct 62 ms 5220 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 1 ms 364 KB Output is correct
6 Correct 0 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 29 ms 2540 KB Output is correct
12 Correct 29 ms 2660 KB Output is correct
13 Correct 28 ms 2404 KB Output is correct
14 Correct 27 ms 2412 KB Output is correct
15 Correct 28 ms 2404 KB Output is correct
16 Correct 26 ms 2408 KB Output is correct
17 Correct 26 ms 2600 KB Output is correct
18 Correct 26 ms 2664 KB Output is correct
19 Correct 24 ms 2412 KB Output is correct
20 Correct 26 ms 2660 KB Output is correct
21 Correct 28 ms 2404 KB Output is correct
22 Correct 25 ms 2668 KB Output is correct
23 Correct 28 ms 2532 KB Output is correct
24 Correct 24 ms 2540 KB Output is correct
25 Correct 27 ms 2532 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 1 ms 364 KB Output is correct
6 Correct 0 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 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 29 ms 2540 KB Output is correct
27 Correct 29 ms 2660 KB Output is correct
28 Correct 28 ms 2404 KB Output is correct
29 Correct 27 ms 2412 KB Output is correct
30 Correct 28 ms 2404 KB Output is correct
31 Correct 56 ms 5092 KB Output is correct
32 Correct 57 ms 5092 KB Output is correct
33 Correct 56 ms 5092 KB Output is correct
34 Correct 57 ms 5092 KB Output is correct
35 Correct 56 ms 5092 KB Output is correct
36 Correct 56 ms 4964 KB Output is correct
37 Correct 59 ms 5092 KB Output is correct
38 Correct 60 ms 5092 KB Output is correct
39 Correct 57 ms 5092 KB Output is correct
40 Correct 62 ms 5220 KB Output is correct
41 Correct 26 ms 2408 KB Output is correct
42 Correct 26 ms 2600 KB Output is correct
43 Correct 26 ms 2664 KB Output is correct
44 Correct 24 ms 2412 KB Output is correct
45 Correct 26 ms 2660 KB Output is correct
46 Correct 28 ms 2404 KB Output is correct
47 Correct 25 ms 2668 KB Output is correct
48 Correct 28 ms 2532 KB Output is correct
49 Correct 24 ms 2540 KB Output is correct
50 Correct 27 ms 2532 KB Output is correct
51 Correct 68 ms 4964 KB Output is correct
52 Correct 66 ms 4836 KB Output is correct
53 Correct 67 ms 4964 KB Output is correct
54 Correct 68 ms 4708 KB Output is correct
55 Correct 67 ms 4964 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 1 ms 364 KB Output is correct
6 Correct 0 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 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 29 ms 2540 KB Output is correct
27 Correct 29 ms 2660 KB Output is correct
28 Correct 28 ms 2404 KB Output is correct
29 Correct 27 ms 2412 KB Output is correct
30 Correct 28 ms 2404 KB Output is correct
31 Correct 56 ms 5092 KB Output is correct
32 Correct 57 ms 5092 KB Output is correct
33 Correct 56 ms 5092 KB Output is correct
34 Correct 57 ms 5092 KB Output is correct
35 Correct 56 ms 5092 KB Output is correct
36 Correct 56 ms 4964 KB Output is correct
37 Correct 59 ms 5092 KB Output is correct
38 Correct 60 ms 5092 KB Output is correct
39 Correct 57 ms 5092 KB Output is correct
40 Correct 62 ms 5220 KB Output is correct
41 Correct 26 ms 2408 KB Output is correct
42 Correct 26 ms 2600 KB Output is correct
43 Correct 26 ms 2664 KB Output is correct
44 Correct 24 ms 2412 KB Output is correct
45 Correct 26 ms 2660 KB Output is correct
46 Correct 28 ms 2404 KB Output is correct
47 Correct 25 ms 2668 KB Output is correct
48 Correct 28 ms 2532 KB Output is correct
49 Correct 24 ms 2540 KB Output is correct
50 Correct 27 ms 2532 KB Output is correct
51 Correct 68 ms 4964 KB Output is correct
52 Correct 66 ms 4836 KB Output is correct
53 Correct 67 ms 4964 KB Output is correct
54 Correct 68 ms 4708 KB Output is correct
55 Correct 67 ms 4964 KB Output is correct
56 Correct 794 ms 40376 KB Output is correct
57 Correct 792 ms 39928 KB Output is correct
58 Correct 755 ms 37856 KB Output is correct
59 Correct 768 ms 38500 KB Output is correct
60 Correct 812 ms 41060 KB Output is correct