답안 #1084951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084951 2024-09-07T09:00:52 Z pemguimn 운세 보기 2 (JOI14_fortune_telling2) C++14
4 / 100
60 ms 8144 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5, VAL = 3 * N, MAX = 4 * VAL;
int n, k, a[N], b[N], t[N], pos[N];

int ans[N];

int seg[MAX];
vector<int> val;

void upd(int id, int tl, int tr, int i, int x){
    if(i < tl || i > tr) return;
    if(tl == tr){
        seg[id] = max(seg[id], x); return;
    }
    int mid = (tl + tr) / 2;
    upd(id * 2, tl, mid, i, x), upd(id * 2 + 1, mid + 1, tr, i, x);
    seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}

int query(int id, int tl, int tr, int l, int r){
    if(r < tl || tr < l) return 0;
    if(l <= tl && tr <= r) return seg[id];
    int mid = (tl + tr) / 2;
    return max(query(id * 2, tl, mid, l, r), query(id * 2 + 1, mid + 1, tr, l, r));
}

int bit[MAX];

void upd(int x, int val){
    for(; x < MAX; x += x & -x){
        bit[x] += val;
    }
}

void upd(int l, int r, int val){
    l++, r++;
    upd(l, val), upd(r + 1, -val);
}

int query(int x){
    x++;
    int ans = 0;
    for(; x; x -= x & -x) ans += bit[x];
    return ans;
}
vector<int> p[N];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i], val.insert(val.end(), {a[i], b[i]});
    for(int i = 1; i <= k; i++) cin >> t[i], val.push_back(t[i]);

    sort(val.begin(), val.end()); val.resize(unique(val.begin(), val.end()) - val.begin());
    for(int i = 1; i <= n; i++) a[i] = lower_bound(val.begin(), val.end(), a[i]) - val.begin(), b[i] = lower_bound(val.begin(), val.end(), b[i]) - val.begin();
    for(int i = 1; i <= k; i++) t[i] = lower_bound(val.begin(), val.end(), t[i]) - val.begin();

    for(int i = 1; i <= k; i++) upd(1, 0, val.size() - 1, t[i], i);

    for(int i = 1; i <= n; i++){
        pos[i] = query(1, 0, val.size() - 1, min(a[i], b[i]), max(a[i], b[i]));
        p[pos[i]].push_back(i);
    }

    for(int i = k; i >= 0; i--){
        if(i) upd(0, t[i], 1);
        for(int x : p[i]){
            int cnt = query(max(a[x], b[x]));
            if(i == 0){
                ans[x] = (cnt & 1 ? b[x] : a[x]);
            } else{
                if(a[x] > b[x]) swap(a[x], b[x]);
                ans[x] = (cnt & 1 ? a[x] : b[x]);
            }
        }
    }

    long long res = 0;
    for(int i = 1; i <= n; i++) res += val[ans[i]];
    cout << res << '\n';
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5268 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5348 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 3 ms 5232 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5268 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5348 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 3 ms 5232 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 14 ms 5980 KB Output is correct
15 Correct 26 ms 6584 KB Output is correct
16 Correct 39 ms 7572 KB Output is correct
17 Correct 54 ms 8140 KB Output is correct
18 Correct 55 ms 8056 KB Output is correct
19 Correct 60 ms 8040 KB Output is correct
20 Correct 53 ms 8144 KB Output is correct
21 Correct 59 ms 8140 KB Output is correct
22 Correct 43 ms 7892 KB Output is correct
23 Incorrect 40 ms 7376 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5268 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5348 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 3 ms 5232 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 14 ms 5980 KB Output is correct
15 Correct 26 ms 6584 KB Output is correct
16 Correct 39 ms 7572 KB Output is correct
17 Correct 54 ms 8140 KB Output is correct
18 Correct 55 ms 8056 KB Output is correct
19 Correct 60 ms 8040 KB Output is correct
20 Correct 53 ms 8144 KB Output is correct
21 Correct 59 ms 8140 KB Output is correct
22 Correct 43 ms 7892 KB Output is correct
23 Incorrect 40 ms 7376 KB Output isn't correct
24 Halted 0 ms 0 KB -