답안 #484077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484077 2021-11-02T05:23:56 Z CyberSleeper Pilot (NOI19_pilot) C++14
100 / 100
598 ms 75780 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define pll         pair<ll, ll>
#define ull         unsigned long long
#define ld          long double
#define pii         pair<ll, ll>
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
using namespace std;

const ll MX=1000007, MOD=1e9+7, BLOCK=330, INF=1e9+7;
const ld ERR=1e-7, pi=3.14159265358979323846;

ll N, Q, H[MX], ptr=0;
ll tot=0, ans[MX];
pii A[MX], Y[MX];

ll calc(ll x){
    return x*(1ll+x)/2ll;
}
struct dsu{
    ll par[MX], sz[MX];
    dsu(){
        for(ll i=0; i<MX; i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    ll f(ll u){
        if(par[u]!=u)
            par[u]=f(par[u]);
        return par[u];
    }
    void join(ll u, ll v){
        u=f(u);
        v=f(v);
        if(u==v)
            return;
        if(sz[u]>sz[v])
            swap(u, v);
        tot-=calc(sz[u])+calc(sz[v]);
        par[u]=v;
        sz[v]+=sz[u];
        tot+=calc(sz[v]);
    }
}DSU;

int main(){
    fastio;
    cin >> N >> Q;
    for(ll i=0; i<N; i++){
        cin >> H[i];
        A[i]={H[i], i};
    }
    for(ll i=0; i<Q; i++){
        cin >> Y[i].fi;
        Y[i].se=i;
    }
    sort(Y, Y+Q);
    sort(A, A+N);
    for(ll i=0; ptr<Q && i<N; i++){
        ll h=A[i].fi, idx=A[i].se;
        while(ptr<Q && Y[ptr].fi<h)
            ans[Y[ptr++].se]=tot;
        tot++;
        if(idx && H[idx-1]<=h)
            DSU.join(idx-1, idx);
        if(idx+1<N && H[idx+1]<=h)
            DSU.join(idx+1, idx);
    }
    while(ptr<Q)
        ans[Y[ptr++].se]=tot;
    for(ll i=0; i<Q; i++){
        cout << ans[i] << nl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
11 Correct 9 ms 15972 KB Output is correct
12 Correct 6 ms 15912 KB Output is correct
13 Correct 7 ms 15976 KB Output is correct
14 Correct 6 ms 15948 KB Output is correct
15 Correct 6 ms 15948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
11 Correct 9 ms 15972 KB Output is correct
12 Correct 6 ms 15912 KB Output is correct
13 Correct 7 ms 15976 KB Output is correct
14 Correct 6 ms 15948 KB Output is correct
15 Correct 6 ms 15948 KB Output is correct
16 Correct 6 ms 15948 KB Output is correct
17 Correct 6 ms 15948 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 16028 KB Output is correct
20 Correct 9 ms 15972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
11 Correct 9 ms 15972 KB Output is correct
12 Correct 6 ms 15912 KB Output is correct
13 Correct 7 ms 15976 KB Output is correct
14 Correct 6 ms 15948 KB Output is correct
15 Correct 6 ms 15948 KB Output is correct
16 Correct 6 ms 15948 KB Output is correct
17 Correct 6 ms 15948 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 16028 KB Output is correct
20 Correct 9 ms 15972 KB Output is correct
21 Correct 7 ms 16076 KB Output is correct
22 Correct 7 ms 15988 KB Output is correct
23 Correct 7 ms 15948 KB Output is correct
24 Correct 7 ms 15948 KB Output is correct
25 Correct 7 ms 15984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 18812 KB Output is correct
2 Correct 26 ms 18892 KB Output is correct
3 Correct 24 ms 18728 KB Output is correct
4 Correct 24 ms 18676 KB Output is correct
5 Correct 30 ms 18644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 22352 KB Output is correct
2 Correct 37 ms 22468 KB Output is correct
3 Correct 39 ms 22376 KB Output is correct
4 Correct 38 ms 22596 KB Output is correct
5 Correct 50 ms 22396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 22456 KB Output is correct
2 Correct 38 ms 22464 KB Output is correct
3 Correct 41 ms 22584 KB Output is correct
4 Correct 51 ms 22596 KB Output is correct
5 Correct 46 ms 22868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
11 Correct 25 ms 18812 KB Output is correct
12 Correct 26 ms 18892 KB Output is correct
13 Correct 24 ms 18728 KB Output is correct
14 Correct 24 ms 18676 KB Output is correct
15 Correct 30 ms 18644 KB Output is correct
16 Correct 24 ms 18676 KB Output is correct
17 Correct 23 ms 18892 KB Output is correct
18 Correct 23 ms 18908 KB Output is correct
19 Correct 20 ms 18560 KB Output is correct
20 Correct 23 ms 18884 KB Output is correct
21 Correct 25 ms 18548 KB Output is correct
22 Correct 22 ms 18704 KB Output is correct
23 Correct 23 ms 18884 KB Output is correct
24 Correct 20 ms 18636 KB Output is correct
25 Correct 31 ms 18676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
11 Correct 9 ms 15972 KB Output is correct
12 Correct 6 ms 15912 KB Output is correct
13 Correct 7 ms 15976 KB Output is correct
14 Correct 6 ms 15948 KB Output is correct
15 Correct 6 ms 15948 KB Output is correct
16 Correct 6 ms 15948 KB Output is correct
17 Correct 6 ms 15948 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 16028 KB Output is correct
20 Correct 9 ms 15972 KB Output is correct
21 Correct 7 ms 16076 KB Output is correct
22 Correct 7 ms 15988 KB Output is correct
23 Correct 7 ms 15948 KB Output is correct
24 Correct 7 ms 15948 KB Output is correct
25 Correct 7 ms 15984 KB Output is correct
26 Correct 25 ms 18812 KB Output is correct
27 Correct 26 ms 18892 KB Output is correct
28 Correct 24 ms 18728 KB Output is correct
29 Correct 24 ms 18676 KB Output is correct
30 Correct 30 ms 18644 KB Output is correct
31 Correct 40 ms 22352 KB Output is correct
32 Correct 37 ms 22468 KB Output is correct
33 Correct 39 ms 22376 KB Output is correct
34 Correct 38 ms 22596 KB Output is correct
35 Correct 50 ms 22396 KB Output is correct
36 Correct 46 ms 22456 KB Output is correct
37 Correct 38 ms 22464 KB Output is correct
38 Correct 41 ms 22584 KB Output is correct
39 Correct 51 ms 22596 KB Output is correct
40 Correct 46 ms 22868 KB Output is correct
41 Correct 24 ms 18676 KB Output is correct
42 Correct 23 ms 18892 KB Output is correct
43 Correct 23 ms 18908 KB Output is correct
44 Correct 20 ms 18560 KB Output is correct
45 Correct 23 ms 18884 KB Output is correct
46 Correct 25 ms 18548 KB Output is correct
47 Correct 22 ms 18704 KB Output is correct
48 Correct 23 ms 18884 KB Output is correct
49 Correct 20 ms 18636 KB Output is correct
50 Correct 31 ms 18676 KB Output is correct
51 Correct 53 ms 22368 KB Output is correct
52 Correct 47 ms 22368 KB Output is correct
53 Correct 55 ms 22452 KB Output is correct
54 Correct 46 ms 22364 KB Output is correct
55 Correct 47 ms 22340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 7 ms 16008 KB Output is correct
4 Correct 8 ms 15912 KB Output is correct
5 Correct 6 ms 15948 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 6 ms 15976 KB Output is correct
8 Correct 7 ms 15948 KB Output is correct
9 Correct 6 ms 15948 KB Output is correct
10 Correct 7 ms 15976 KB Output is correct
11 Correct 9 ms 15972 KB Output is correct
12 Correct 6 ms 15912 KB Output is correct
13 Correct 7 ms 15976 KB Output is correct
14 Correct 6 ms 15948 KB Output is correct
15 Correct 6 ms 15948 KB Output is correct
16 Correct 6 ms 15948 KB Output is correct
17 Correct 6 ms 15948 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 16028 KB Output is correct
20 Correct 9 ms 15972 KB Output is correct
21 Correct 7 ms 16076 KB Output is correct
22 Correct 7 ms 15988 KB Output is correct
23 Correct 7 ms 15948 KB Output is correct
24 Correct 7 ms 15948 KB Output is correct
25 Correct 7 ms 15984 KB Output is correct
26 Correct 25 ms 18812 KB Output is correct
27 Correct 26 ms 18892 KB Output is correct
28 Correct 24 ms 18728 KB Output is correct
29 Correct 24 ms 18676 KB Output is correct
30 Correct 30 ms 18644 KB Output is correct
31 Correct 40 ms 22352 KB Output is correct
32 Correct 37 ms 22468 KB Output is correct
33 Correct 39 ms 22376 KB Output is correct
34 Correct 38 ms 22596 KB Output is correct
35 Correct 50 ms 22396 KB Output is correct
36 Correct 46 ms 22456 KB Output is correct
37 Correct 38 ms 22464 KB Output is correct
38 Correct 41 ms 22584 KB Output is correct
39 Correct 51 ms 22596 KB Output is correct
40 Correct 46 ms 22868 KB Output is correct
41 Correct 24 ms 18676 KB Output is correct
42 Correct 23 ms 18892 KB Output is correct
43 Correct 23 ms 18908 KB Output is correct
44 Correct 20 ms 18560 KB Output is correct
45 Correct 23 ms 18884 KB Output is correct
46 Correct 25 ms 18548 KB Output is correct
47 Correct 22 ms 18704 KB Output is correct
48 Correct 23 ms 18884 KB Output is correct
49 Correct 20 ms 18636 KB Output is correct
50 Correct 31 ms 18676 KB Output is correct
51 Correct 53 ms 22368 KB Output is correct
52 Correct 47 ms 22368 KB Output is correct
53 Correct 55 ms 22452 KB Output is correct
54 Correct 46 ms 22364 KB Output is correct
55 Correct 47 ms 22340 KB Output is correct
56 Correct 598 ms 74832 KB Output is correct
57 Correct 526 ms 74256 KB Output is correct
58 Correct 496 ms 71500 KB Output is correct
59 Correct 498 ms 72564 KB Output is correct
60 Correct 577 ms 75780 KB Output is correct