Submission #484080

# Submission time Handle Problem Language Result Execution time Memory
484080 2021-11-02T05:26:49 Z CyberSleeper Pilot (NOI19_pilot) C++14
100 / 100
560 ms 69888 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#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;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
11 Correct 6 ms 15948 KB Output is correct
12 Correct 7 ms 15948 KB Output is correct
13 Correct 6 ms 15948 KB Output is correct
14 Correct 6 ms 15948 KB Output is correct
15 Correct 6 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
11 Correct 6 ms 15948 KB Output is correct
12 Correct 7 ms 15948 KB Output is correct
13 Correct 6 ms 15948 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 15908 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 15948 KB Output is correct
20 Correct 7 ms 15924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
11 Correct 6 ms 15948 KB Output is correct
12 Correct 7 ms 15948 KB Output is correct
13 Correct 6 ms 15948 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 15908 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 15948 KB Output is correct
20 Correct 7 ms 15924 KB Output is correct
21 Correct 8 ms 15948 KB Output is correct
22 Correct 8 ms 15948 KB Output is correct
23 Correct 8 ms 15948 KB Output is correct
24 Correct 10 ms 15948 KB Output is correct
25 Correct 7 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 18252 KB Output is correct
2 Correct 25 ms 18252 KB Output is correct
3 Correct 24 ms 18124 KB Output is correct
4 Correct 24 ms 18096 KB Output is correct
5 Correct 26 ms 18156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 21188 KB Output is correct
2 Correct 39 ms 21316 KB Output is correct
3 Correct 41 ms 21316 KB Output is correct
4 Correct 38 ms 21444 KB Output is correct
5 Correct 42 ms 21316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 21260 KB Output is correct
2 Correct 42 ms 21332 KB Output is correct
3 Correct 41 ms 21316 KB Output is correct
4 Correct 39 ms 21316 KB Output is correct
5 Correct 55 ms 21548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
11 Correct 25 ms 18252 KB Output is correct
12 Correct 25 ms 18252 KB Output is correct
13 Correct 24 ms 18124 KB Output is correct
14 Correct 24 ms 18096 KB Output is correct
15 Correct 26 ms 18156 KB Output is correct
16 Correct 27 ms 18124 KB Output is correct
17 Correct 22 ms 18264 KB Output is correct
18 Correct 21 ms 18316 KB Output is correct
19 Correct 21 ms 18072 KB Output is correct
20 Correct 24 ms 18244 KB Output is correct
21 Correct 25 ms 18036 KB Output is correct
22 Correct 21 ms 18036 KB Output is correct
23 Correct 26 ms 18252 KB Output is correct
24 Correct 21 ms 18120 KB Output is correct
25 Correct 23 ms 18252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
11 Correct 6 ms 15948 KB Output is correct
12 Correct 7 ms 15948 KB Output is correct
13 Correct 6 ms 15948 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 15908 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 15948 KB Output is correct
20 Correct 7 ms 15924 KB Output is correct
21 Correct 8 ms 15948 KB Output is correct
22 Correct 8 ms 15948 KB Output is correct
23 Correct 8 ms 15948 KB Output is correct
24 Correct 10 ms 15948 KB Output is correct
25 Correct 7 ms 15948 KB Output is correct
26 Correct 25 ms 18252 KB Output is correct
27 Correct 25 ms 18252 KB Output is correct
28 Correct 24 ms 18124 KB Output is correct
29 Correct 24 ms 18096 KB Output is correct
30 Correct 26 ms 18156 KB Output is correct
31 Correct 37 ms 21188 KB Output is correct
32 Correct 39 ms 21316 KB Output is correct
33 Correct 41 ms 21316 KB Output is correct
34 Correct 38 ms 21444 KB Output is correct
35 Correct 42 ms 21316 KB Output is correct
36 Correct 41 ms 21260 KB Output is correct
37 Correct 42 ms 21332 KB Output is correct
38 Correct 41 ms 21316 KB Output is correct
39 Correct 39 ms 21316 KB Output is correct
40 Correct 55 ms 21548 KB Output is correct
41 Correct 27 ms 18124 KB Output is correct
42 Correct 22 ms 18264 KB Output is correct
43 Correct 21 ms 18316 KB Output is correct
44 Correct 21 ms 18072 KB Output is correct
45 Correct 24 ms 18244 KB Output is correct
46 Correct 25 ms 18036 KB Output is correct
47 Correct 21 ms 18036 KB Output is correct
48 Correct 26 ms 18252 KB Output is correct
49 Correct 21 ms 18120 KB Output is correct
50 Correct 23 ms 18252 KB Output is correct
51 Correct 51 ms 21280 KB Output is correct
52 Correct 47 ms 21116 KB Output is correct
53 Correct 47 ms 21312 KB Output is correct
54 Correct 48 ms 21040 KB Output is correct
55 Correct 59 ms 21164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 6 ms 15948 KB Output is correct
3 Correct 6 ms 15948 KB Output is correct
4 Correct 6 ms 15948 KB Output is correct
5 Correct 6 ms 15924 KB Output is correct
6 Correct 6 ms 15948 KB Output is correct
7 Correct 9 ms 15992 KB Output is correct
8 Correct 8 ms 15948 KB Output is correct
9 Correct 7 ms 15948 KB Output is correct
10 Correct 7 ms 15948 KB Output is correct
11 Correct 6 ms 15948 KB Output is correct
12 Correct 7 ms 15948 KB Output is correct
13 Correct 6 ms 15948 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 15908 KB Output is correct
18 Correct 6 ms 15948 KB Output is correct
19 Correct 8 ms 15948 KB Output is correct
20 Correct 7 ms 15924 KB Output is correct
21 Correct 8 ms 15948 KB Output is correct
22 Correct 8 ms 15948 KB Output is correct
23 Correct 8 ms 15948 KB Output is correct
24 Correct 10 ms 15948 KB Output is correct
25 Correct 7 ms 15948 KB Output is correct
26 Correct 25 ms 18252 KB Output is correct
27 Correct 25 ms 18252 KB Output is correct
28 Correct 24 ms 18124 KB Output is correct
29 Correct 24 ms 18096 KB Output is correct
30 Correct 26 ms 18156 KB Output is correct
31 Correct 37 ms 21188 KB Output is correct
32 Correct 39 ms 21316 KB Output is correct
33 Correct 41 ms 21316 KB Output is correct
34 Correct 38 ms 21444 KB Output is correct
35 Correct 42 ms 21316 KB Output is correct
36 Correct 41 ms 21260 KB Output is correct
37 Correct 42 ms 21332 KB Output is correct
38 Correct 41 ms 21316 KB Output is correct
39 Correct 39 ms 21316 KB Output is correct
40 Correct 55 ms 21548 KB Output is correct
41 Correct 27 ms 18124 KB Output is correct
42 Correct 22 ms 18264 KB Output is correct
43 Correct 21 ms 18316 KB Output is correct
44 Correct 21 ms 18072 KB Output is correct
45 Correct 24 ms 18244 KB Output is correct
46 Correct 25 ms 18036 KB Output is correct
47 Correct 21 ms 18036 KB Output is correct
48 Correct 26 ms 18252 KB Output is correct
49 Correct 21 ms 18120 KB Output is correct
50 Correct 23 ms 18252 KB Output is correct
51 Correct 51 ms 21280 KB Output is correct
52 Correct 47 ms 21116 KB Output is correct
53 Correct 47 ms 21312 KB Output is correct
54 Correct 48 ms 21040 KB Output is correct
55 Correct 59 ms 21164 KB Output is correct
56 Correct 560 ms 68816 KB Output is correct
57 Correct 523 ms 68228 KB Output is correct
58 Correct 488 ms 65524 KB Output is correct
59 Correct 492 ms 66524 KB Output is correct
60 Correct 520 ms 69888 KB Output is correct