답안 #223578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223578 2020-04-15T13:54:33 Z jovan_b 운세 보기 2 (JOI14_fortune_telling2) C++17
35 / 100
556 ms 48760 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

int a[200005];
int b[200005];
int sp[25][200005];
int g[200005];
int treba[200005];
int lg[200005];
int bit[300005];

pair <int, int> t[200005];

int k;

int nadji(int x){
    /// poslednji manji jednak x
    int l = 1, r = k, res = 0;
    while(l <= r){
        int mid = (l+r)/2;
        if(t[mid].first <= x){
            l = mid+1;
            res = mid;
        }
        else r = mid-1;
    }
    return res;
}

int getmax(int l, int r){
    int j = lg[r-l+1];
    return max(sp[j][l], sp[j][r-(1<<j)+1]);
}

int bitget(int x){
    int res = 0;
    while(x){
        res += bit[x];
        x -= x & -x;
    }
    return res;
}

void bitadd(int x){
    while(x <= 300000){
        bit[x]++;
        x += x & -x;
    }
}

map <int, int> u;
vector <int> vec[200005];
int kolko[200005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n >> k;
    for(int i=2; i<=k; i++){
        lg[i] = 1 + lg[i/2];
    }
    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i=1; i<=k; i++){
        cin >> t[i].first;
        t[i].second = i;
        g[i] = t[i].first;
    }
    sort(t+1, t+1+k);
    for(int i=1; i<=k; i++){
        sp[0][i] = t[i].second;
    }
    for(int j=1; (1<<j)<=k; j++){
        for(int i=1; i+(1<<j)-1<=k; i++){
            sp[j][i] = max(sp[j-1][i], sp[j-1][i+(1<<(j-1))]);
        }
    }
    for(int i=1; i<=n; i++){
        int p = min(a[i], b[i]);
        int d = max(a[i], b[i]);
        int x = nadji(p-1);
        int y = nadji(d-1);
        if(x >= y) continue;
        treba[i] = getmax(x+1, y);
    }
    vector <int> comp;
    for(int i=1; i<=n; i++){
        vec[treba[i]+1].push_back(i);
    }
    for(int i=1; i<=n; i++){
        comp.push_back(a[i]);
        comp.push_back(b[i]);
    }
    for(int i=1; i<=k; i++){
        comp.push_back(g[i]);
    }
    sort(comp.begin(), comp.end());
    int cmpr = 0;
    for(auto c : comp){
        if(!u[c]) u[c] = ++cmpr;
    }
    for(int i=k; i>=1; i--){
        bitadd(u[g[i]]);
        for(auto c : vec[i]){
            kolko[c] = k-i+1 - bitget(u[min(a[c], b[c])]);
        }
    }
    ll res = 0;
    for(int i=1; i<=n; i++){
        //cout << i << " " << treba[i] << " " << kolko[i] << endl;
        kolko[i] %= 2;
        if(a[i] >= b[i] || treba[i] == 0){
            if(kolko[i]) res += b[i];
            else res += a[i];
        }
        else{
            if(kolko[i]) res += a[i];
            else res += b[i];
        }
    }
    cout << res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5376 KB Output is correct
3 Correct 10 ms 5504 KB Output is correct
4 Correct 9 ms 5376 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 9 ms 5504 KB Output is correct
7 Correct 11 ms 5504 KB Output is correct
8 Correct 9 ms 5376 KB Output is correct
9 Correct 9 ms 5376 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 10 ms 5376 KB Output is correct
12 Correct 9 ms 5376 KB Output is correct
13 Correct 9 ms 5376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5376 KB Output is correct
3 Correct 10 ms 5504 KB Output is correct
4 Correct 9 ms 5376 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 9 ms 5504 KB Output is correct
7 Correct 11 ms 5504 KB Output is correct
8 Correct 9 ms 5376 KB Output is correct
9 Correct 9 ms 5376 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 10 ms 5376 KB Output is correct
12 Correct 9 ms 5376 KB Output is correct
13 Correct 9 ms 5376 KB Output is correct
14 Correct 29 ms 8064 KB Output is correct
15 Correct 60 ms 10888 KB Output is correct
16 Correct 82 ms 13680 KB Output is correct
17 Correct 123 ms 16620 KB Output is correct
18 Correct 117 ms 16624 KB Output is correct
19 Correct 112 ms 16624 KB Output is correct
20 Correct 118 ms 16664 KB Output is correct
21 Correct 107 ms 16564 KB Output is correct
22 Correct 96 ms 14244 KB Output is correct
23 Correct 78 ms 13040 KB Output is correct
24 Correct 81 ms 12388 KB Output is correct
25 Correct 93 ms 14700 KB Output is correct
26 Correct 83 ms 13932 KB Output is correct
27 Correct 98 ms 14616 KB Output is correct
28 Correct 84 ms 14644 KB Output is correct
29 Correct 117 ms 15732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5376 KB Output is correct
3 Correct 10 ms 5504 KB Output is correct
4 Correct 9 ms 5376 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 9 ms 5504 KB Output is correct
7 Correct 11 ms 5504 KB Output is correct
8 Correct 9 ms 5376 KB Output is correct
9 Correct 9 ms 5376 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 10 ms 5376 KB Output is correct
12 Correct 9 ms 5376 KB Output is correct
13 Correct 9 ms 5376 KB Output is correct
14 Correct 29 ms 8064 KB Output is correct
15 Correct 60 ms 10888 KB Output is correct
16 Correct 82 ms 13680 KB Output is correct
17 Correct 123 ms 16620 KB Output is correct
18 Correct 117 ms 16624 KB Output is correct
19 Correct 112 ms 16624 KB Output is correct
20 Correct 118 ms 16664 KB Output is correct
21 Correct 107 ms 16564 KB Output is correct
22 Correct 96 ms 14244 KB Output is correct
23 Correct 78 ms 13040 KB Output is correct
24 Correct 81 ms 12388 KB Output is correct
25 Correct 93 ms 14700 KB Output is correct
26 Correct 83 ms 13932 KB Output is correct
27 Correct 98 ms 14616 KB Output is correct
28 Correct 84 ms 14644 KB Output is correct
29 Correct 117 ms 15732 KB Output is correct
30 Correct 308 ms 35664 KB Output is correct
31 Correct 442 ms 41744 KB Output is correct
32 Incorrect 556 ms 48760 KB Output isn't correct
33 Halted 0 ms 0 KB -