Submission #54572

# Submission time Handle Problem Language Result Execution time Memory
54572 2018-07-04T06:43:59 Z ikura355 Fortune Telling 2 (JOI14_fortune_telling2) C++14
0 / 100
7 ms 5144 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 5;

int n,m;
int a[maxn], b[maxn], c[maxn];
int limit;
int pos[maxn], res[maxn];
vector<int> p[maxn];

int sz, tree[maxn*9];
int fen[maxn*3];
map<int,int> mp;
int rec[maxn*3];

void cpidx() {
    for(int i=1;i<=n;i++) mp[a[i]], mp[b[i]];
    for(int i=1;i<=m;i++) mp[c[i]];
    for(auto &it : mp) {
        it.second = ++sz;
        rec[sz] = it.first;
    }
    for(int i=1;i<=n;i++) a[i] = mp[a[i]], b[i] = mp[b[i]];
    for(int i=1;i<=m;i++) c[i] = mp[c[i]];
}
void init() {
    limit = 1;
    while(limit<=sz) limit*=2;
}
void update(int x, int val) {
    x += limit;
    tree[x] = max(tree[x], val);
    while(x) {
        x/=2;
        tree[x] = max(tree[x<<1], tree[x<<1|1]);
    }
}
int query(int l, int r) {
    l += limit; r += limit;
    int res = 0;
    while(l<r) {
        if(l%2==0) res = max(res, tree[l++]);
        if(r%2==1) res = max(res, tree[r--]);
        l/=2; r/=2;
    }
    if(l==r) res = max(res, tree[l]);
    return res;
}
void add(int x, int val) {
    while(x) {
        fen[x] += val;
        x -= x&-x;
    }
}
int sum(int x) {
    int res = 0;
    while(x<=sz) {
        res += fen[x];
        x += x&-x;
    }
    return res;
}
int main() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    for(int i=1;i<=m;i++) scanf("%d",&c[i]);
    cpidx();
    init();
    for(int i=1;i<=m;i++) update(c[i], i);
    for(int i=1;i<=n;i++) {
        pos[i] = query(min(a[i],b[i]), max(a[i],b[i])-1);
        p[pos[i]+1].push_back(i);
    }
    for(int i=m;i>=1;i--) {
        add(c[i],1);
        for(auto x : p[i]) res[x] = sum(max(a[x], b[x]));
    }
    long long ans = 0;
    for(int i=1;i<=n;i++) {
//        printf("%d : pos = %d res = %d\n",i,pos[i],res[i]);
        if(pos[i]==0) {
            if(res[i]%2==0) ans += rec[a[i]];//, printf("%d ",rec[a[i]]);
            else ans += rec[b[i]];//, printf("%d ",rec[b[i]]);
        }
        else {
            if(res[i]%2==1) ans += rec[min(a[i], b[i])];//, printf("%d ",rec[min(a[i], b[i])]);
            else ans += rec[max(a[i], b[i])];//, printf("%d ",rec[max(a[i], b[i])]);
        }
    }
    printf("%lld",ans);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
fortune_telling2.cpp:66:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:67:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=m;i++) scanf("%d",&c[i]);
                           ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5144 KB Output isn't correct
2 Halted 0 ms 0 KB -