답안 #488540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488540 2021-11-19T14:47:17 Z Joo Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 62944 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6+10, INF = 1e9+7;
using ll = long long;
using pi = pair<int,int>;

int n,Q,h[N],num,sz[N];
ll ans, ansp[N];
vector<pi> vec,qq;
map<int, int> E,S; //E for end point of subarray, S for start point of subarray

void rem(int id){
    bool okl = false, okr = false;
    auto ir = S.upper_bound(id);
    if(ir != S.end() and ir->first == id+1){ //the current is connected to the previous subarray to the left
        okr = true;
    }
    auto il = E.lower_bound(id);
    if(il != E.begin()){
        il--;
        if(il->first == id-1)
            okl = true;
    }    

    if (!okl and !okr){ //create new subarray
        E[id] = ++num;
        S[id] = num;
        sz[num] = 1;
        ans += 1;
    } else if(okl and okr){ //merge left and right subarray together
        int tid = il->second; //change index of end point of right side to this one
        int tsr = sz[ir->second], tsl = sz[il->second];
        int tsz = tsr + tsl + 1;
        ans -= 1ll*tsr*(tsr+1)/2; //delete previous ans and add new one later
        ans -= 1ll*tsl*(tsl+1)/2;
        ans += 1ll*tsz*(tsz+1)/2;

        auto ire = E.lower_bound(ir->first);
        ire->second = tid;
        sz[tid] = tsr + tsl + 1;

        S.erase(ir);
        E.erase(il);
    } else if(okr){
        int tid = ir->second;
        int tsr = sz[tid];
        ans -= 1ll*tsr*(tsr+1)/2;
        ans += 1ll*(tsr+1)*(tsr+2)/2;

        sz[tid]++;
        S.erase(ir);
        S[id] = tid;
    } else if(okl){
        int tid = il->second;
        int tsl = sz[tid];
        ans -= 1ll*tsl*(tsl+1)/2;
        ans += 1ll*(tsl+1)*(tsl+2)/2;

        sz[tid]++;
        E.erase(il);
        E[id] = tid;
    }
    return;
}

int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> Q;
    for(int i = 1; i <= n; i++){
        cin >> h[i];
        vec.emplace_back(h[i], i);
    }

    for(int i = 1; i <= Q; i++){
        int x; cin >> x;
        qq.emplace_back(x, i);
    }

    sort(qq.begin(), qq.end());
    sort(vec.begin(), vec.end());

    int vi = 0; //pointer of vector's index
    for(auto [want, iq] : qq){
        while(vi < n and vec[vi].first <= want){
            rem(vec[vi].second);
            vi++;
        }
        ansp[iq] = ans;
    }

    for(int i = 1; i <= Q; i++){
        cout << ansp[i] << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 3812 KB Output is correct
2 Correct 68 ms 4152 KB Output is correct
3 Correct 71 ms 4000 KB Output is correct
4 Correct 62 ms 3952 KB Output is correct
5 Correct 65 ms 4028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3936 KB Output is correct
2 Correct 38 ms 5116 KB Output is correct
3 Correct 37 ms 5052 KB Output is correct
4 Correct 39 ms 5160 KB Output is correct
5 Correct 36 ms 5064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 3904 KB Output is correct
2 Correct 37 ms 5232 KB Output is correct
3 Correct 38 ms 5248 KB Output is correct
4 Correct 38 ms 5248 KB Output is correct
5 Correct 38 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 76 ms 3812 KB Output is correct
12 Correct 68 ms 4152 KB Output is correct
13 Correct 71 ms 4000 KB Output is correct
14 Correct 62 ms 3952 KB Output is correct
15 Correct 65 ms 4028 KB Output is correct
16 Correct 52 ms 4024 KB Output is correct
17 Correct 35 ms 3956 KB Output is correct
18 Correct 22 ms 2700 KB Output is correct
19 Correct 20 ms 2508 KB Output is correct
20 Correct 42 ms 4080 KB Output is correct
21 Correct 66 ms 3908 KB Output is correct
22 Correct 43 ms 3984 KB Output is correct
23 Correct 31 ms 3688 KB Output is correct
24 Correct 24 ms 3036 KB Output is correct
25 Correct 43 ms 4120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 76 ms 3812 KB Output is correct
27 Correct 68 ms 4152 KB Output is correct
28 Correct 71 ms 4000 KB Output is correct
29 Correct 62 ms 3952 KB Output is correct
30 Correct 65 ms 4028 KB Output is correct
31 Correct 36 ms 3936 KB Output is correct
32 Correct 38 ms 5116 KB Output is correct
33 Correct 37 ms 5052 KB Output is correct
34 Correct 39 ms 5160 KB Output is correct
35 Correct 36 ms 5064 KB Output is correct
36 Correct 35 ms 3904 KB Output is correct
37 Correct 37 ms 5232 KB Output is correct
38 Correct 38 ms 5248 KB Output is correct
39 Correct 38 ms 5248 KB Output is correct
40 Correct 38 ms 5456 KB Output is correct
41 Correct 52 ms 4024 KB Output is correct
42 Correct 35 ms 3956 KB Output is correct
43 Correct 22 ms 2700 KB Output is correct
44 Correct 20 ms 2508 KB Output is correct
45 Correct 42 ms 4080 KB Output is correct
46 Correct 66 ms 3908 KB Output is correct
47 Correct 43 ms 3984 KB Output is correct
48 Correct 31 ms 3688 KB Output is correct
49 Correct 24 ms 3036 KB Output is correct
50 Correct 43 ms 4120 KB Output is correct
51 Correct 90 ms 7224 KB Output is correct
52 Correct 90 ms 7240 KB Output is correct
53 Correct 95 ms 7304 KB Output is correct
54 Correct 90 ms 7100 KB Output is correct
55 Correct 92 ms 7360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 76 ms 3812 KB Output is correct
27 Correct 68 ms 4152 KB Output is correct
28 Correct 71 ms 4000 KB Output is correct
29 Correct 62 ms 3952 KB Output is correct
30 Correct 65 ms 4028 KB Output is correct
31 Correct 36 ms 3936 KB Output is correct
32 Correct 38 ms 5116 KB Output is correct
33 Correct 37 ms 5052 KB Output is correct
34 Correct 39 ms 5160 KB Output is correct
35 Correct 36 ms 5064 KB Output is correct
36 Correct 35 ms 3904 KB Output is correct
37 Correct 37 ms 5232 KB Output is correct
38 Correct 38 ms 5248 KB Output is correct
39 Correct 38 ms 5248 KB Output is correct
40 Correct 38 ms 5456 KB Output is correct
41 Correct 52 ms 4024 KB Output is correct
42 Correct 35 ms 3956 KB Output is correct
43 Correct 22 ms 2700 KB Output is correct
44 Correct 20 ms 2508 KB Output is correct
45 Correct 42 ms 4080 KB Output is correct
46 Correct 66 ms 3908 KB Output is correct
47 Correct 43 ms 3984 KB Output is correct
48 Correct 31 ms 3688 KB Output is correct
49 Correct 24 ms 3036 KB Output is correct
50 Correct 43 ms 4120 KB Output is correct
51 Correct 90 ms 7224 KB Output is correct
52 Correct 90 ms 7240 KB Output is correct
53 Correct 95 ms 7304 KB Output is correct
54 Correct 90 ms 7100 KB Output is correct
55 Correct 92 ms 7360 KB Output is correct
56 Execution timed out 1093 ms 62944 KB Time limit exceeded
57 Halted 0 ms 0 KB -