Submission #239820

# Submission time Handle Problem Language Result Execution time Memory
239820 2020-06-17T10:46:33 Z mhy908 Pilot (NOI19_pilot) C++14
100 / 100
990 ms 72312 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long LL;
int n, q;
vector<int> vc[1000010];
LL ans[1000010], nans, tmp, sz[1000010];
bool ch[1000010];
int par[1000010];
int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);}
void mergepar(int a, int b){
    a=findpar(a);
    b=findpar(b);
    if(a==b)return;
    nans-=sz[a]*(sz[a]+1)/2;
    nans-=sz[b]*(sz[b]+1)/2;
    sz[a]+=sz[b];
    par[b]=a;
    nans+=sz[a]*(sz[a]+1)/2;
}
int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=1000000; i++)par[i]=i, sz[i]=1;
    nans=(LL)n;
    tmp=(LL)n;
    for(int i=1; i<=n; i++){
        int a;
        scanf("%d", &a);
        vc[a].eb(i);
    }
    for(int i=1; i<=1000000; i++){
        for(auto j:vc[i]){
            ch[j]=true;
            if(ch[j+1])mergepar(j, j+1);
            if(ch[j-1])mergepar(j-1, j);
            tmp--;
        }
        ans[i]=nans-tmp;
    }
    for(int i=1; i<=q; i++){
        int a;
        scanf("%d", &a);
        printf("%lld\n", ans[a]);
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
pilot.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
pilot.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
11 Correct 34 ms 43384 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 31 ms 43384 KB Output is correct
14 Correct 36 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
11 Correct 34 ms 43384 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 31 ms 43384 KB Output is correct
14 Correct 36 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 35 ms 43384 KB Output is correct
17 Correct 35 ms 43384 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 31 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
11 Correct 34 ms 43384 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 31 ms 43384 KB Output is correct
14 Correct 36 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 35 ms 43384 KB Output is correct
17 Correct 35 ms 43384 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 31 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
21 Correct 31 ms 43392 KB Output is correct
22 Correct 31 ms 43384 KB Output is correct
23 Correct 31 ms 43384 KB Output is correct
24 Correct 32 ms 43392 KB Output is correct
25 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 45432 KB Output is correct
2 Correct 77 ms 46328 KB Output is correct
3 Correct 59 ms 45308 KB Output is correct
4 Correct 72 ms 46200 KB Output is correct
5 Correct 61 ms 45304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 47456 KB Output is correct
2 Correct 100 ms 47480 KB Output is correct
3 Correct 82 ms 47352 KB Output is correct
4 Correct 86 ms 47480 KB Output is correct
5 Correct 82 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 47480 KB Output is correct
2 Correct 88 ms 47356 KB Output is correct
3 Correct 91 ms 47352 KB Output is correct
4 Correct 93 ms 47556 KB Output is correct
5 Correct 95 ms 47480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
11 Correct 61 ms 45432 KB Output is correct
12 Correct 77 ms 46328 KB Output is correct
13 Correct 59 ms 45308 KB Output is correct
14 Correct 72 ms 46200 KB Output is correct
15 Correct 61 ms 45304 KB Output is correct
16 Correct 60 ms 45304 KB Output is correct
17 Correct 77 ms 46328 KB Output is correct
18 Correct 84 ms 46456 KB Output is correct
19 Correct 62 ms 45304 KB Output is correct
20 Correct 79 ms 46328 KB Output is correct
21 Correct 60 ms 45304 KB Output is correct
22 Correct 76 ms 46200 KB Output is correct
23 Correct 63 ms 45432 KB Output is correct
24 Correct 77 ms 46200 KB Output is correct
25 Correct 60 ms 45432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
11 Correct 34 ms 43384 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 31 ms 43384 KB Output is correct
14 Correct 36 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 35 ms 43384 KB Output is correct
17 Correct 35 ms 43384 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 31 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
21 Correct 31 ms 43392 KB Output is correct
22 Correct 31 ms 43384 KB Output is correct
23 Correct 31 ms 43384 KB Output is correct
24 Correct 32 ms 43392 KB Output is correct
25 Correct 31 ms 43392 KB Output is correct
26 Correct 61 ms 45432 KB Output is correct
27 Correct 77 ms 46328 KB Output is correct
28 Correct 59 ms 45308 KB Output is correct
29 Correct 72 ms 46200 KB Output is correct
30 Correct 61 ms 45304 KB Output is correct
31 Correct 92 ms 47456 KB Output is correct
32 Correct 100 ms 47480 KB Output is correct
33 Correct 82 ms 47352 KB Output is correct
34 Correct 86 ms 47480 KB Output is correct
35 Correct 82 ms 47352 KB Output is correct
36 Correct 88 ms 47480 KB Output is correct
37 Correct 88 ms 47356 KB Output is correct
38 Correct 91 ms 47352 KB Output is correct
39 Correct 93 ms 47556 KB Output is correct
40 Correct 95 ms 47480 KB Output is correct
41 Correct 60 ms 45304 KB Output is correct
42 Correct 77 ms 46328 KB Output is correct
43 Correct 84 ms 46456 KB Output is correct
44 Correct 62 ms 45304 KB Output is correct
45 Correct 79 ms 46328 KB Output is correct
46 Correct 60 ms 45304 KB Output is correct
47 Correct 76 ms 46200 KB Output is correct
48 Correct 63 ms 45432 KB Output is correct
49 Correct 77 ms 46200 KB Output is correct
50 Correct 60 ms 45432 KB Output is correct
51 Correct 93 ms 46200 KB Output is correct
52 Correct 109 ms 46968 KB Output is correct
53 Correct 93 ms 46200 KB Output is correct
54 Correct 116 ms 46968 KB Output is correct
55 Correct 98 ms 46200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 31 ms 43384 KB Output is correct
3 Correct 30 ms 43392 KB Output is correct
4 Correct 30 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43384 KB Output is correct
7 Correct 31 ms 43384 KB Output is correct
8 Correct 31 ms 43384 KB Output is correct
9 Correct 30 ms 43392 KB Output is correct
10 Correct 31 ms 43392 KB Output is correct
11 Correct 34 ms 43384 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 31 ms 43384 KB Output is correct
14 Correct 36 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 35 ms 43384 KB Output is correct
17 Correct 35 ms 43384 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 31 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
21 Correct 31 ms 43392 KB Output is correct
22 Correct 31 ms 43384 KB Output is correct
23 Correct 31 ms 43384 KB Output is correct
24 Correct 32 ms 43392 KB Output is correct
25 Correct 31 ms 43392 KB Output is correct
26 Correct 61 ms 45432 KB Output is correct
27 Correct 77 ms 46328 KB Output is correct
28 Correct 59 ms 45308 KB Output is correct
29 Correct 72 ms 46200 KB Output is correct
30 Correct 61 ms 45304 KB Output is correct
31 Correct 92 ms 47456 KB Output is correct
32 Correct 100 ms 47480 KB Output is correct
33 Correct 82 ms 47352 KB Output is correct
34 Correct 86 ms 47480 KB Output is correct
35 Correct 82 ms 47352 KB Output is correct
36 Correct 88 ms 47480 KB Output is correct
37 Correct 88 ms 47356 KB Output is correct
38 Correct 91 ms 47352 KB Output is correct
39 Correct 93 ms 47556 KB Output is correct
40 Correct 95 ms 47480 KB Output is correct
41 Correct 60 ms 45304 KB Output is correct
42 Correct 77 ms 46328 KB Output is correct
43 Correct 84 ms 46456 KB Output is correct
44 Correct 62 ms 45304 KB Output is correct
45 Correct 79 ms 46328 KB Output is correct
46 Correct 60 ms 45304 KB Output is correct
47 Correct 76 ms 46200 KB Output is correct
48 Correct 63 ms 45432 KB Output is correct
49 Correct 77 ms 46200 KB Output is correct
50 Correct 60 ms 45432 KB Output is correct
51 Correct 93 ms 46200 KB Output is correct
52 Correct 109 ms 46968 KB Output is correct
53 Correct 93 ms 46200 KB Output is correct
54 Correct 116 ms 46968 KB Output is correct
55 Correct 98 ms 46200 KB Output is correct
56 Correct 928 ms 70684 KB Output is correct
57 Correct 990 ms 71244 KB Output is correct
58 Correct 902 ms 70108 KB Output is correct
59 Correct 909 ms 71416 KB Output is correct
60 Correct 953 ms 72312 KB Output is correct