답안 #619958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
619958 2022-08-02T17:39:56 Z Ahmadsm2005 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
454 ms 33764 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int N,K,A[200000],B[200000],KK[200000],seg[800000];
bool Z[200000];
vector<pair<int,int>>KS;
ordered_set SPP;
bool COMP(pair<int,int>A,pair<int,int>B){
    return max(A.first,A.second) > max(B.first,B.second);
}
void UPD(int T, int v, int L = 0, int R = 200000, int idx = 0){
    if(L == R && L == T){seg[idx] = v;return;}
    else if(L > T || R < T)return;
    UPD(T,v,L,(L + R) / 2,idx * 2 + 1);
    UPD(T,v,(L + R) / 2 + 1, R, idx * 2 + 2);
    seg[idx] = max(seg[idx * 2 + 1], seg[idx * 2 + 2]);
}
int query(int v,int LL = 0, int RR = 200000, int idx = 0){
    if(LL == RR){
        return LL;
    }
    else if(seg[idx * 2 + 2] >= v)return query(v,(LL + RR) / 2 + 1,RR,idx * 2 + 2);
    else if(seg[idx * 2 + 1] >= v)return query(v,LL,(LL + RR) / 2, idx * 2 + 1);
    return -1;
}
int32_t main()
{
    cin.tie(0),iostream::sync_with_stdio(0);
    cin>>N>>K;
    for(int i = 0; i < N; i += 1){
        cin>>A[i]>>B[i];
    }
    SPP.insert(-1),SPP.insert(K);
    for(int i = 0; i < K; i += 1)cin >> KK[i],KS.push_back({KK[i],i}),UPD(i,KK[i]);
    vector<pair<int,int>>SP;
    for(int i = 0; i < N; i += 1)SP.push_back({A[i],B[i]});
    sort(SP.begin(),SP.end(),COMP);
    sort(KS.begin(),KS.end());
    int CNT = 0,ANS = 0;
    for(int i = 0; i < N; i += 1){
        int MX = max(SP[i].first,SP[i].second);
        while(KS.size()){
            if(KS.back().first >= MX){
                int idx = KS.back().second;
                UPD(idx,0);
                SPP.insert(idx);
                CNT++;
                KS.pop_back();
            }
            else break;
        }
        int F = query(min(SP[i].first,SP[i].second));
        //cout<<"lol: "<<F<<endl;
        if(F + 1){
            int R = (SPP.size() - SPP.order_of_key(F) + (SP[i].first < SP[i].second)) % 2;
            ANS += (R?SP[i].first:SP[i].second);
        }
        else{
            //cout<<(((SP[i].first < SP[i].second) + CNT + 1) % 2)<<endl;
            ANS += (((CNT + 1) % 2)?SP[i].first:SP[i].second);
        }
    }
    cout<<ANS;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 14 ms 1968 KB Output is correct
15 Correct 26 ms 3696 KB Output is correct
16 Correct 43 ms 5312 KB Output is correct
17 Correct 51 ms 6964 KB Output is correct
18 Correct 57 ms 6996 KB Output is correct
19 Correct 45 ms 6376 KB Output is correct
20 Correct 57 ms 6988 KB Output is correct
21 Correct 34 ms 5412 KB Output is correct
22 Correct 35 ms 5212 KB Output is correct
23 Correct 41 ms 5708 KB Output is correct
24 Correct 44 ms 6292 KB Output is correct
25 Correct 35 ms 4940 KB Output is correct
26 Correct 51 ms 6716 KB Output is correct
27 Correct 60 ms 7048 KB Output is correct
28 Correct 55 ms 7056 KB Output is correct
29 Correct 51 ms 6992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 14 ms 1968 KB Output is correct
15 Correct 26 ms 3696 KB Output is correct
16 Correct 43 ms 5312 KB Output is correct
17 Correct 51 ms 6964 KB Output is correct
18 Correct 57 ms 6996 KB Output is correct
19 Correct 45 ms 6376 KB Output is correct
20 Correct 57 ms 6988 KB Output is correct
21 Correct 34 ms 5412 KB Output is correct
22 Correct 35 ms 5212 KB Output is correct
23 Correct 41 ms 5708 KB Output is correct
24 Correct 44 ms 6292 KB Output is correct
25 Correct 35 ms 4940 KB Output is correct
26 Correct 51 ms 6716 KB Output is correct
27 Correct 60 ms 7048 KB Output is correct
28 Correct 55 ms 7056 KB Output is correct
29 Correct 51 ms 6992 KB Output is correct
30 Correct 333 ms 23880 KB Output is correct
31 Correct 305 ms 26040 KB Output is correct
32 Correct 401 ms 28616 KB Output is correct
33 Correct 375 ms 33616 KB Output is correct
34 Correct 108 ms 13392 KB Output is correct
35 Correct 386 ms 33612 KB Output is correct
36 Correct 424 ms 33664 KB Output is correct
37 Correct 348 ms 33640 KB Output is correct
38 Correct 280 ms 29980 KB Output is correct
39 Correct 399 ms 33616 KB Output is correct
40 Correct 182 ms 24012 KB Output is correct
41 Correct 337 ms 32500 KB Output is correct
42 Correct 337 ms 33340 KB Output is correct
43 Correct 137 ms 23520 KB Output is correct
44 Correct 137 ms 23464 KB Output is correct
45 Correct 143 ms 23464 KB Output is correct
46 Correct 241 ms 27564 KB Output is correct
47 Correct 454 ms 31588 KB Output is correct
48 Correct 317 ms 33764 KB Output is correct
49 Correct 310 ms 33740 KB Output is correct