답안 #641435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641435 2022-09-16T17:52:06 Z ttamx Pilot (NOI19_pilot) C++14
100 / 100
571 ms 57044 KB
#include<bits/stdc++.h>

using namespace std;

const int N=1e6+5;

int n,q;
int p[N];
long long sz[N],ans[N];
long long sum=0;
bool vis[N];
vector<pair<int,int>> a,b;

int fp(int u){
    if(u==p[u])return u;
    return p[u]=fp(p[u]);
}

void merg(int u,int v){
    u=fp(u),v=fp(v);
    sum-=sz[u]*(sz[u]+1)/2;
    sum-=sz[v]*(sz[v]+1)/2;
    p[v]=u;
    sz[u]+=sz[v];
    sz[v]=0;
    sum+=sz[u]*(sz[u]+1)/2;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> q;
    iota(p,p+n+1,0);
    for(int i=1;i<=n;++i){
        int x;
        cin >> x;
        a.emplace_back(x,i);
        sz[i]=1;
    }
    for(int i=1;i<=q;++i){
        int x;
        cin >> x;
        b.emplace_back(x,i);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int idx=0;
    for(auto [h,i]:b){
        while(idx<n && a[idx].first<=h){
            vis[a[idx].second]=1;
            ++sum;
            if(vis[a[idx].second-1])merg(a[idx].second-1,a[idx].second);
            if(vis[a[idx].second+1])merg(a[idx].second+1,a[idx].second);
            ++idx;
        }
        ans[i]=sum;
    }
    for(int i=1;i<=q;++i)cout << ans[i] << '\n';
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:47:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     for(auto [h,i]:b){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2916 KB Output is correct
2 Correct 23 ms 3076 KB Output is correct
3 Correct 19 ms 2912 KB Output is correct
4 Correct 20 ms 2928 KB Output is correct
5 Correct 19 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5900 KB Output is correct
2 Correct 42 ms 5964 KB Output is correct
3 Correct 40 ms 5868 KB Output is correct
4 Correct 35 ms 6036 KB Output is correct
5 Correct 35 ms 5912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5972 KB Output is correct
2 Correct 40 ms 6064 KB Output is correct
3 Correct 41 ms 6060 KB Output is correct
4 Correct 40 ms 6068 KB Output is correct
5 Correct 42 ms 6236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 21 ms 2916 KB Output is correct
12 Correct 23 ms 3076 KB Output is correct
13 Correct 19 ms 2912 KB Output is correct
14 Correct 20 ms 2928 KB Output is correct
15 Correct 19 ms 2900 KB Output is correct
16 Correct 18 ms 2896 KB Output is correct
17 Correct 18 ms 3068 KB Output is correct
18 Correct 17 ms 3144 KB Output is correct
19 Correct 18 ms 2900 KB Output is correct
20 Correct 18 ms 3100 KB Output is correct
21 Correct 19 ms 2900 KB Output is correct
22 Correct 18 ms 2952 KB Output is correct
23 Correct 24 ms 3000 KB Output is correct
24 Correct 16 ms 2900 KB Output is correct
25 Correct 17 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 21 ms 2916 KB Output is correct
27 Correct 23 ms 3076 KB Output is correct
28 Correct 19 ms 2912 KB Output is correct
29 Correct 20 ms 2928 KB Output is correct
30 Correct 19 ms 2900 KB Output is correct
31 Correct 35 ms 5900 KB Output is correct
32 Correct 42 ms 5964 KB Output is correct
33 Correct 40 ms 5868 KB Output is correct
34 Correct 35 ms 6036 KB Output is correct
35 Correct 35 ms 5912 KB Output is correct
36 Correct 35 ms 5972 KB Output is correct
37 Correct 40 ms 6064 KB Output is correct
38 Correct 41 ms 6060 KB Output is correct
39 Correct 40 ms 6068 KB Output is correct
40 Correct 42 ms 6236 KB Output is correct
41 Correct 18 ms 2896 KB Output is correct
42 Correct 18 ms 3068 KB Output is correct
43 Correct 17 ms 3144 KB Output is correct
44 Correct 18 ms 2900 KB Output is correct
45 Correct 18 ms 3100 KB Output is correct
46 Correct 19 ms 2900 KB Output is correct
47 Correct 18 ms 2952 KB Output is correct
48 Correct 24 ms 3000 KB Output is correct
49 Correct 16 ms 2900 KB Output is correct
50 Correct 17 ms 2936 KB Output is correct
51 Correct 46 ms 5888 KB Output is correct
52 Correct 50 ms 5772 KB Output is correct
53 Correct 45 ms 5928 KB Output is correct
54 Correct 46 ms 5708 KB Output is correct
55 Correct 44 ms 5832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 21 ms 2916 KB Output is correct
27 Correct 23 ms 3076 KB Output is correct
28 Correct 19 ms 2912 KB Output is correct
29 Correct 20 ms 2928 KB Output is correct
30 Correct 19 ms 2900 KB Output is correct
31 Correct 35 ms 5900 KB Output is correct
32 Correct 42 ms 5964 KB Output is correct
33 Correct 40 ms 5868 KB Output is correct
34 Correct 35 ms 6036 KB Output is correct
35 Correct 35 ms 5912 KB Output is correct
36 Correct 35 ms 5972 KB Output is correct
37 Correct 40 ms 6064 KB Output is correct
38 Correct 41 ms 6060 KB Output is correct
39 Correct 40 ms 6068 KB Output is correct
40 Correct 42 ms 6236 KB Output is correct
41 Correct 18 ms 2896 KB Output is correct
42 Correct 18 ms 3068 KB Output is correct
43 Correct 17 ms 3144 KB Output is correct
44 Correct 18 ms 2900 KB Output is correct
45 Correct 18 ms 3100 KB Output is correct
46 Correct 19 ms 2900 KB Output is correct
47 Correct 18 ms 2952 KB Output is correct
48 Correct 24 ms 3000 KB Output is correct
49 Correct 16 ms 2900 KB Output is correct
50 Correct 17 ms 2936 KB Output is correct
51 Correct 46 ms 5888 KB Output is correct
52 Correct 50 ms 5772 KB Output is correct
53 Correct 45 ms 5928 KB Output is correct
54 Correct 46 ms 5708 KB Output is correct
55 Correct 44 ms 5832 KB Output is correct
56 Correct 571 ms 55848 KB Output is correct
57 Correct 557 ms 55276 KB Output is correct
58 Correct 504 ms 52456 KB Output is correct
59 Correct 522 ms 53544 KB Output is correct
60 Correct 533 ms 57044 KB Output is correct