답안 #519498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519498 2022-01-26T12:40:33 Z pokmui9909 운세 보기 2 (JOI14_fortune_telling2) C++17
35 / 100
1286 ms 123472 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll S = (1 << 19);
struct MaxSegTree{
    ll T[2 * S] = {};
    void update(ll k, ll v) { update(1, 1, S, k, v); }
    ll query(ll l, ll r) { return query(1, 1, S, l, r); }
    void update(ll node, ll s, ll e, ll k, ll v){
        if (s == e){
            T[node] = max(T[node], v);
            return;
        }
        ll m = (s + e) / 2;
        ll lch = 2 * node, rch = 2 * node + 1;
        if (k <= m) update(lch, s, m, k, v);
        else update(rch, m + 1, e, k, v);
        ll x = T[lch], y = T[rch];
        T[node] = max(x, y);
    }
    ll query(ll node, ll s, ll e, ll l, ll r){
        if (e < l || s > r) return 0;
        if (l <= s && e <= r) return T[node];
        ll m = (s + e) / 2;
        ll lch = 2 * node, rch = 2 * node + 1;
        ll x = query(lch, s, m, l, r), y = query(rch, m + 1, e, l, r);
        return max(x, y);
    }
};
struct MergeSortTree{
    vector<ll> T[2 * S];
    ll query(ll l, ll r, ll k) {return query(1, 1, S / 2, l, r, k);}
    void init(){
        for(int i = S / 2 - 1; i >= 1; i--){
            vector<ll> &L = T[i * 2], &R = T[i * 2 + 1];
            T[i].resize(L.size() + R.size());
            merge(L.begin(), L.end(), R.begin(), R.end(), T[i].begin());
        }
    }
    void push(ll k, ll v){
        T[k + S / 2 - 1].push_back(v);
    }
    ll query(ll node, ll s, ll e, ll l, ll r, ll v){
        if(e < l || s > r) return 0;
        if(l <= s && e <= r) return T[node].end() - lower_bound(T[node].begin(), T[node].end(), v);
        ll m = (s + e) / 2, lch = node * 2, rch = node * 2 + 1;
        ll x = query(lch, s, m, l, r, v);
        ll y = query(rch, m + 1, e, l, r, v);
        return x + y;
    }
};
vector<ll> V;
map<ll, ll> mp;
MaxSegTree MT;
MergeSortTree SRT;
ll Index(ll n){
    return lower_bound(V.begin(), V.end(), n) - V.begin() + 1;
}
ll N, K;
ll A[200005];
ll B[200005];
ll Q[200005];
  
int main(){
    cin.tie(0) -> sync_with_stdio(false);
  
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
        cin >> A[i] >> B[i];
        V.push_back(A[i]); V.push_back(B[i]);
    }
    for(int i = 1; i <= K; i++){
        cin >> Q[i];
        V.push_back(Q[i]);
    }
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());
    for(int i = 1; i <= N; i++){
        mp[Index(A[i])] = A[i];
        A[i] = Index(A[i]);
        mp[Index(B[i])] = B[i];
        B[i] = Index(B[i]);
    }
    for(int i = 1; i <= K; i++){
        mp[Index(Q[i])] = Q[i];
        Q[i] = Index(Q[i]);
        MT.update(Q[i], i);
        SRT.push(i, Q[i]);
    }
    SRT.init();
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        ll C = min(A[i], B[i]), D = max(A[i], B[i]);
        ll Last = MT.query(C, D - 1);
        ll R = SRT.query(Last + 1, K, D);
        if(Last == 0) C = B[i], D = A[i];
        if(R % 2 == 0){
            ans += mp[D];
        } else {
            ans += mp[C];
        }
    }
    cout << ans;
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 25292 KB Output is correct
2 Correct 22 ms 25292 KB Output is correct
3 Correct 19 ms 25388 KB Output is correct
4 Correct 21 ms 25412 KB Output is correct
5 Correct 23 ms 25516 KB Output is correct
6 Correct 19 ms 25384 KB Output is correct
7 Correct 18 ms 25420 KB Output is correct
8 Correct 20 ms 25452 KB Output is correct
9 Correct 17 ms 25484 KB Output is correct
10 Correct 16 ms 25344 KB Output is correct
11 Correct 17 ms 25348 KB Output is correct
12 Correct 20 ms 25324 KB Output is correct
13 Correct 22 ms 25404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 25292 KB Output is correct
2 Correct 22 ms 25292 KB Output is correct
3 Correct 19 ms 25388 KB Output is correct
4 Correct 21 ms 25412 KB Output is correct
5 Correct 23 ms 25516 KB Output is correct
6 Correct 19 ms 25384 KB Output is correct
7 Correct 18 ms 25420 KB Output is correct
8 Correct 20 ms 25452 KB Output is correct
9 Correct 17 ms 25484 KB Output is correct
10 Correct 16 ms 25344 KB Output is correct
11 Correct 17 ms 25348 KB Output is correct
12 Correct 20 ms 25324 KB Output is correct
13 Correct 22 ms 25404 KB Output is correct
14 Correct 45 ms 29988 KB Output is correct
15 Correct 86 ms 34868 KB Output is correct
16 Correct 137 ms 39928 KB Output is correct
17 Correct 194 ms 44900 KB Output is correct
18 Correct 180 ms 44836 KB Output is correct
19 Correct 189 ms 44932 KB Output is correct
20 Correct 184 ms 44904 KB Output is correct
21 Correct 157 ms 44824 KB Output is correct
22 Correct 142 ms 41228 KB Output is correct
23 Correct 103 ms 39684 KB Output is correct
24 Correct 102 ms 38600 KB Output is correct
25 Correct 124 ms 42440 KB Output is correct
26 Correct 113 ms 40932 KB Output is correct
27 Correct 154 ms 41772 KB Output is correct
28 Correct 121 ms 41804 KB Output is correct
29 Correct 189 ms 43492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 25292 KB Output is correct
2 Correct 22 ms 25292 KB Output is correct
3 Correct 19 ms 25388 KB Output is correct
4 Correct 21 ms 25412 KB Output is correct
5 Correct 23 ms 25516 KB Output is correct
6 Correct 19 ms 25384 KB Output is correct
7 Correct 18 ms 25420 KB Output is correct
8 Correct 20 ms 25452 KB Output is correct
9 Correct 17 ms 25484 KB Output is correct
10 Correct 16 ms 25344 KB Output is correct
11 Correct 17 ms 25348 KB Output is correct
12 Correct 20 ms 25324 KB Output is correct
13 Correct 22 ms 25404 KB Output is correct
14 Correct 45 ms 29988 KB Output is correct
15 Correct 86 ms 34868 KB Output is correct
16 Correct 137 ms 39928 KB Output is correct
17 Correct 194 ms 44900 KB Output is correct
18 Correct 180 ms 44836 KB Output is correct
19 Correct 189 ms 44932 KB Output is correct
20 Correct 184 ms 44904 KB Output is correct
21 Correct 157 ms 44824 KB Output is correct
22 Correct 142 ms 41228 KB Output is correct
23 Correct 103 ms 39684 KB Output is correct
24 Correct 102 ms 38600 KB Output is correct
25 Correct 124 ms 42440 KB Output is correct
26 Correct 113 ms 40932 KB Output is correct
27 Correct 154 ms 41772 KB Output is correct
28 Correct 121 ms 41804 KB Output is correct
29 Correct 189 ms 43492 KB Output is correct
30 Correct 398 ms 85296 KB Output is correct
31 Correct 578 ms 93636 KB Output is correct
32 Correct 804 ms 104024 KB Output is correct
33 Incorrect 1286 ms 123472 KB Output isn't correct
34 Halted 0 ms 0 KB -