Submission #647708

# Submission time Handle Problem Language Result Execution time Memory
647708 2022-10-03T18:11:45 Z Ronin13 Fortune Telling 2 (JOI14_fortune_telling2) C++14
100 / 100
1424 ms 75120 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

int lsb(int x){
    return x & -x;
}
const int NMAX = 1e6 + 1;
vector <int> bit(NMAX);
int n;
void add(int v, int val){
    while(v < NMAX){
        bit[v] += val;
        v += lsb(v);
    }
}

int get(int pos){
    int sum = 0;
    while(pos){
        sum += bit[pos];
        pos -= lsb(pos);
    }
    return sum;
}

int sum(int l, int r){
    return get(r) - get(l - 1);
}

vector <int> t(4 * NMAX);

void update(int v, int l, int r, int pos, int val){
    if(l > pos || r < pos) return;
    if(l == r){
        t[v] = max(val, t[v]);
        return;
    }
    int m = (l + r) / 2;
    update(2 * v, l, m, pos, val);
    update(2 * v + 1, m + 1, r, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}
int get(int v, int l, int r, int st, int fin){
    if(l > fin || r < st) return 0;
    if(l >= st && r <= fin) return t[v];
    int m = (l + r) / 2;
    return max(get(2 * v, l, m, st, fin),
               get(2 * v + 1, m + 1, r, st, fin));
}
map <int,int> mp;

int main(){
    cin >> n;
    int k; cin >> k;
    int a[n + 1], b[n + 1];
    int cur[n + 1];
    vector <int> vec;
    for(int i= 1; i<= n; i++){
        cin >> a[i] >> b[i];
        vec.pb(a[i]);
        vec.pb(b[i]);
        if(a[i] <= b[i]) cur[i] = 1;
        else cur[i] = 0;
    }
    int t[k + 1];
    for(int i = 1; i <= k; i++)
        cin >> t[i];
    for(int i = 1; i <= k; i++)
        vec.pb(t[i]);
    sort(vec.begin(), vec.end());
    for(int i = 0; i < vec.size(); i++){
        int x = vec[i];
        mp[x] = i + 1;
    }
    for(int i = k; i >= 1; i--){
        int v = t[i]; v = mp[v];
        update(1, 1, 2 * n + k, v, i);
    }
    ll ans = 0;
    vector <vector <int> > qv(2 * n + k + 1);
    for(int i = 1; i <= n; i++){
        int v = min(a[i], b[i]);
        int u = max(a[i], b[i]);
        int x = mp[v], y = mp[u]; y--;
        int val = get(1, 1, 2 * n + k, x, y);
        //cout << val << "\n";
        qv[val].pb(i);
    }
    for(int i = k; i >= 1; i--){
        int x= t[i]; x = mp[x];
        add(x, 1);
        for(int to : qv[i]){
            int r = max(b[to], a[to]); r= mp[r];
            int v = sum(r, NMAX - 1);
            //cout << v << ' ' ;
            if(v % 2 == 0) ans += (ll)max(b[to], a[to]);
            else ans += (ll)min(b[to], a[to]);
        }
        //cout << "\n";
    }
    for(int to : qv[0]){
        int r = max(b[to], a[to]); r = mp[r];
        int v = sum(r, NMAX - 1);
        v += cur[to];
        if(v & 1) ans += (ll)min(b[to], a[to]);
        else ans += (ll)max(b[to], a[to]);
    }
    cout << ans;
    return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 0; i < vec.size(); i++){
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19868 KB Output is correct
2 Correct 11 ms 19952 KB Output is correct
3 Correct 12 ms 20052 KB Output is correct
4 Correct 12 ms 20160 KB Output is correct
5 Correct 12 ms 20052 KB Output is correct
6 Correct 13 ms 20152 KB Output is correct
7 Correct 12 ms 20152 KB Output is correct
8 Correct 12 ms 20064 KB Output is correct
9 Correct 11 ms 20060 KB Output is correct
10 Correct 10 ms 20020 KB Output is correct
11 Correct 10 ms 20028 KB Output is correct
12 Correct 11 ms 20056 KB Output is correct
13 Correct 11 ms 20052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19868 KB Output is correct
2 Correct 11 ms 19952 KB Output is correct
3 Correct 12 ms 20052 KB Output is correct
4 Correct 12 ms 20160 KB Output is correct
5 Correct 12 ms 20052 KB Output is correct
6 Correct 13 ms 20152 KB Output is correct
7 Correct 12 ms 20152 KB Output is correct
8 Correct 12 ms 20064 KB Output is correct
9 Correct 11 ms 20060 KB Output is correct
10 Correct 10 ms 20020 KB Output is correct
11 Correct 10 ms 20028 KB Output is correct
12 Correct 11 ms 20056 KB Output is correct
13 Correct 11 ms 20052 KB Output is correct
14 Correct 43 ms 22624 KB Output is correct
15 Correct 76 ms 25396 KB Output is correct
16 Correct 122 ms 28088 KB Output is correct
17 Correct 187 ms 30744 KB Output is correct
18 Correct 206 ms 30708 KB Output is correct
19 Correct 202 ms 30888 KB Output is correct
20 Correct 193 ms 30824 KB Output is correct
21 Correct 198 ms 30944 KB Output is correct
22 Correct 126 ms 28356 KB Output is correct
23 Correct 126 ms 27544 KB Output is correct
24 Correct 113 ms 26732 KB Output is correct
25 Correct 132 ms 29128 KB Output is correct
26 Correct 132 ms 28052 KB Output is correct
27 Correct 147 ms 28904 KB Output is correct
28 Correct 148 ms 28960 KB Output is correct
29 Correct 155 ms 29972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19868 KB Output is correct
2 Correct 11 ms 19952 KB Output is correct
3 Correct 12 ms 20052 KB Output is correct
4 Correct 12 ms 20160 KB Output is correct
5 Correct 12 ms 20052 KB Output is correct
6 Correct 13 ms 20152 KB Output is correct
7 Correct 12 ms 20152 KB Output is correct
8 Correct 12 ms 20064 KB Output is correct
9 Correct 11 ms 20060 KB Output is correct
10 Correct 10 ms 20020 KB Output is correct
11 Correct 10 ms 20028 KB Output is correct
12 Correct 11 ms 20056 KB Output is correct
13 Correct 11 ms 20052 KB Output is correct
14 Correct 43 ms 22624 KB Output is correct
15 Correct 76 ms 25396 KB Output is correct
16 Correct 122 ms 28088 KB Output is correct
17 Correct 187 ms 30744 KB Output is correct
18 Correct 206 ms 30708 KB Output is correct
19 Correct 202 ms 30888 KB Output is correct
20 Correct 193 ms 30824 KB Output is correct
21 Correct 198 ms 30944 KB Output is correct
22 Correct 126 ms 28356 KB Output is correct
23 Correct 126 ms 27544 KB Output is correct
24 Correct 113 ms 26732 KB Output is correct
25 Correct 132 ms 29128 KB Output is correct
26 Correct 132 ms 28052 KB Output is correct
27 Correct 147 ms 28904 KB Output is correct
28 Correct 148 ms 28960 KB Output is correct
29 Correct 155 ms 29972 KB Output is correct
30 Correct 417 ms 39336 KB Output is correct
31 Correct 608 ms 46868 KB Output is correct
32 Correct 823 ms 55976 KB Output is correct
33 Correct 1424 ms 74804 KB Output is correct
34 Correct 356 ms 37388 KB Output is correct
35 Correct 1418 ms 74720 KB Output is correct
36 Correct 1389 ms 74604 KB Output is correct
37 Correct 1399 ms 74724 KB Output is correct
38 Correct 1373 ms 74712 KB Output is correct
39 Correct 1404 ms 74552 KB Output is correct
40 Correct 1230 ms 75120 KB Output is correct
41 Correct 1363 ms 74496 KB Output is correct
42 Correct 1352 ms 74648 KB Output is correct
43 Correct 714 ms 74528 KB Output is correct
44 Correct 743 ms 74508 KB Output is correct
45 Correct 753 ms 74520 KB Output is correct
46 Correct 773 ms 58664 KB Output is correct
47 Correct 675 ms 53756 KB Output is correct
48 Correct 851 ms 65332 KB Output is correct
49 Correct 898 ms 65564 KB Output is correct