Submission #239815

# Submission time Handle Problem Language Result Execution time Memory
239815 2020-06-17T10:41:54 Z mhy908 Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 72016 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;
int n, q;
vector<int> vc[1000010];
LL ans[1000010], nans, tmp;
bool ch[1000010];
struct UNION_FIND{
    int par[1000010];
    LL sz[1000010];
    UNION_FIND(){for(int i=1; i<=1000000; i++)par[i]=i, sz[i]=1;}
    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;
    }
}uf;
int main(){
    scanf("%d %d", &n, &q);
    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])uf.mergepar(j, j+1);
            if(ch[j-1])uf.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:45: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:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
pilot.cpp:64: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 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
11 Correct 30 ms 43392 KB Output is correct
12 Correct 30 ms 43392 KB Output is correct
13 Correct 33 ms 43384 KB Output is correct
14 Correct 30 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
11 Correct 30 ms 43392 KB Output is correct
12 Correct 30 ms 43392 KB Output is correct
13 Correct 33 ms 43384 KB Output is correct
14 Correct 30 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 33 ms 43384 KB Output is correct
17 Correct 31 ms 43392 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 30 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
11 Correct 30 ms 43392 KB Output is correct
12 Correct 30 ms 43392 KB Output is correct
13 Correct 33 ms 43384 KB Output is correct
14 Correct 30 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 33 ms 43384 KB Output is correct
17 Correct 31 ms 43392 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 30 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
21 Correct 34 ms 43392 KB Output is correct
22 Correct 38 ms 43392 KB Output is correct
23 Correct 32 ms 43392 KB Output is correct
24 Correct 40 ms 43384 KB Output is correct
25 Correct 31 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 45432 KB Output is correct
2 Correct 82 ms 46456 KB Output is correct
3 Correct 91 ms 45308 KB Output is correct
4 Correct 75 ms 46200 KB Output is correct
5 Correct 74 ms 45304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 47352 KB Output is correct
2 Correct 101 ms 47480 KB Output is correct
3 Correct 101 ms 47352 KB Output is correct
4 Correct 85 ms 47480 KB Output is correct
5 Correct 95 ms 47284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 47352 KB Output is correct
2 Correct 92 ms 47352 KB Output is correct
3 Correct 105 ms 47352 KB Output is correct
4 Correct 90 ms 47484 KB Output is correct
5 Correct 94 ms 47480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
11 Correct 62 ms 45432 KB Output is correct
12 Correct 82 ms 46456 KB Output is correct
13 Correct 91 ms 45308 KB Output is correct
14 Correct 75 ms 46200 KB Output is correct
15 Correct 74 ms 45304 KB Output is correct
16 Correct 60 ms 45308 KB Output is correct
17 Correct 78 ms 46332 KB Output is correct
18 Correct 77 ms 46456 KB Output is correct
19 Correct 59 ms 45304 KB Output is correct
20 Correct 103 ms 46328 KB Output is correct
21 Correct 59 ms 45304 KB Output is correct
22 Correct 75 ms 46200 KB Output is correct
23 Correct 62 ms 45432 KB Output is correct
24 Correct 75 ms 46200 KB Output is correct
25 Correct 61 ms 45432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
11 Correct 30 ms 43392 KB Output is correct
12 Correct 30 ms 43392 KB Output is correct
13 Correct 33 ms 43384 KB Output is correct
14 Correct 30 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 33 ms 43384 KB Output is correct
17 Correct 31 ms 43392 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 30 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
21 Correct 34 ms 43392 KB Output is correct
22 Correct 38 ms 43392 KB Output is correct
23 Correct 32 ms 43392 KB Output is correct
24 Correct 40 ms 43384 KB Output is correct
25 Correct 31 ms 43392 KB Output is correct
26 Correct 62 ms 45432 KB Output is correct
27 Correct 82 ms 46456 KB Output is correct
28 Correct 91 ms 45308 KB Output is correct
29 Correct 75 ms 46200 KB Output is correct
30 Correct 74 ms 45304 KB Output is correct
31 Correct 94 ms 47352 KB Output is correct
32 Correct 101 ms 47480 KB Output is correct
33 Correct 101 ms 47352 KB Output is correct
34 Correct 85 ms 47480 KB Output is correct
35 Correct 95 ms 47284 KB Output is correct
36 Correct 96 ms 47352 KB Output is correct
37 Correct 92 ms 47352 KB Output is correct
38 Correct 105 ms 47352 KB Output is correct
39 Correct 90 ms 47484 KB Output is correct
40 Correct 94 ms 47480 KB Output is correct
41 Correct 60 ms 45308 KB Output is correct
42 Correct 78 ms 46332 KB Output is correct
43 Correct 77 ms 46456 KB Output is correct
44 Correct 59 ms 45304 KB Output is correct
45 Correct 103 ms 46328 KB Output is correct
46 Correct 59 ms 45304 KB Output is correct
47 Correct 75 ms 46200 KB Output is correct
48 Correct 62 ms 45432 KB Output is correct
49 Correct 75 ms 46200 KB Output is correct
50 Correct 61 ms 45432 KB Output is correct
51 Correct 100 ms 46200 KB Output is correct
52 Correct 112 ms 46968 KB Output is correct
53 Correct 122 ms 46204 KB Output is correct
54 Correct 134 ms 46940 KB Output is correct
55 Correct 93 ms 46200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 43520 KB Output is correct
2 Correct 33 ms 43392 KB Output is correct
3 Correct 37 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 30 ms 43384 KB Output is correct
6 Correct 34 ms 43392 KB Output is correct
7 Correct 31 ms 43392 KB Output is correct
8 Correct 39 ms 43384 KB Output is correct
9 Correct 39 ms 43392 KB Output is correct
10 Correct 30 ms 43392 KB Output is correct
11 Correct 30 ms 43392 KB Output is correct
12 Correct 30 ms 43392 KB Output is correct
13 Correct 33 ms 43384 KB Output is correct
14 Correct 30 ms 43384 KB Output is correct
15 Correct 31 ms 43392 KB Output is correct
16 Correct 33 ms 43384 KB Output is correct
17 Correct 31 ms 43392 KB Output is correct
18 Correct 30 ms 43392 KB Output is correct
19 Correct 30 ms 43392 KB Output is correct
20 Correct 31 ms 43392 KB Output is correct
21 Correct 34 ms 43392 KB Output is correct
22 Correct 38 ms 43392 KB Output is correct
23 Correct 32 ms 43392 KB Output is correct
24 Correct 40 ms 43384 KB Output is correct
25 Correct 31 ms 43392 KB Output is correct
26 Correct 62 ms 45432 KB Output is correct
27 Correct 82 ms 46456 KB Output is correct
28 Correct 91 ms 45308 KB Output is correct
29 Correct 75 ms 46200 KB Output is correct
30 Correct 74 ms 45304 KB Output is correct
31 Correct 94 ms 47352 KB Output is correct
32 Correct 101 ms 47480 KB Output is correct
33 Correct 101 ms 47352 KB Output is correct
34 Correct 85 ms 47480 KB Output is correct
35 Correct 95 ms 47284 KB Output is correct
36 Correct 96 ms 47352 KB Output is correct
37 Correct 92 ms 47352 KB Output is correct
38 Correct 105 ms 47352 KB Output is correct
39 Correct 90 ms 47484 KB Output is correct
40 Correct 94 ms 47480 KB Output is correct
41 Correct 60 ms 45308 KB Output is correct
42 Correct 78 ms 46332 KB Output is correct
43 Correct 77 ms 46456 KB Output is correct
44 Correct 59 ms 45304 KB Output is correct
45 Correct 103 ms 46328 KB Output is correct
46 Correct 59 ms 45304 KB Output is correct
47 Correct 75 ms 46200 KB Output is correct
48 Correct 62 ms 45432 KB Output is correct
49 Correct 75 ms 46200 KB Output is correct
50 Correct 61 ms 45432 KB Output is correct
51 Correct 100 ms 46200 KB Output is correct
52 Correct 112 ms 46968 KB Output is correct
53 Correct 122 ms 46204 KB Output is correct
54 Correct 134 ms 46940 KB Output is correct
55 Correct 93 ms 46200 KB Output is correct
56 Correct 968 ms 70824 KB Output is correct
57 Execution timed out 1057 ms 72016 KB Time limit exceeded
58 Halted 0 ms 0 KB -