답안 #52797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52797 2018-06-26T18:53:46 Z Smelskiy 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
264 ms 106376 KB
#include <bits/stdc++.h>
using namespace std;


int n,m;
pair<int,int> a[200005];
pair<int,int> b[200005];
int t[3000005];
int tt[3000005];
long long ans;
int x,y;
int pos;
int xx;
int sz;

inline bool cmp(pair<int,int> x,pair<int,int> y) {
    return max(x.first,x.second)<max(y.first,y.second);
}


inline void update(int x,int y) {
    x+=sz-1;
    t[x]++;
    tt[x]=y;
    x>>=1;
    while (x) {
        t[x]=t[x+x]+t[x+x+1];
        tt[x]=max(tt[x+x],tt[x+x+1]);
        x>>=1;
    }
}

int get_pos(int l,int r,int x,int y) {
    if (tt[x]<y) return 0;
    if (l==r) return l;
    int mid=(l+r)>>1;
    int res=get_pos(mid+1,r,x+x+1,y);
    if (!res) res=get_pos(l,mid,x+x,y);
    return res;
}

int get_cnt(int l,int r,int ll,int rr,int x) {
    if (l>r || ll>r || l>rr || ll>rr) return 0;
    if (l>=ll && r<=rr) return t[x];
    int mid=(l+r)>>1;
    return get_cnt(l,mid,ll,rr,x+x)+get_cnt(mid+1,r,ll,rr,x+x+1);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;++i)
        cin>>a[i].first>>a[i].second;
    sort(a+1,a+n+1,cmp);
    for (int i=1;i<=m;++i) {
        cin>>b[i].first;
        b[i].second=i;
    }
    sort(b+1,b+m+1);
    int last=1;
    sz=1;
    bool z=false;
    while (sz<m) sz+=sz;
    for (int i=1;i<=n;++i) {
        x=max(a[i].first,a[i].second);
        y=min(a[i].first,a[i].second);
        if (x==y) {
            ans+=x;
            continue;
        }
        while (last<=m && b[last].first<x) {
            update(b[last].second,b[last].first);
            ++last;
        }
        pos=get_pos(1,sz,1,y);
        if (pos) z=true;
        else z=false;
        ++pos;
        xx=get_cnt(1,sz,pos,m,1);
//        cout<<x<<" "<<y<<" "<<pos<<" "<<xx<<'\n';
        xx=m-pos+1-xx;
        xx%=2;
        if (z) {
            if (xx) ans+=y;
            else ans+=x;
        } else {
            if (xx) ans+=a[i].second;
            else ans+=a[i].first;
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 532 KB Output is correct
4 Correct 4 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 4 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 3 ms 832 KB Output is correct
10 Correct 3 ms 832 KB Output is correct
11 Correct 3 ms 832 KB Output is correct
12 Correct 3 ms 832 KB Output is correct
13 Correct 3 ms 832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 532 KB Output is correct
4 Correct 4 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 4 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 3 ms 832 KB Output is correct
10 Correct 3 ms 832 KB Output is correct
11 Correct 3 ms 832 KB Output is correct
12 Correct 3 ms 832 KB Output is correct
13 Correct 3 ms 832 KB Output is correct
14 Correct 13 ms 1416 KB Output is correct
15 Correct 19 ms 1936 KB Output is correct
16 Correct 27 ms 2308 KB Output is correct
17 Correct 36 ms 2688 KB Output is correct
18 Correct 35 ms 3332 KB Output is correct
19 Correct 36 ms 3332 KB Output is correct
20 Correct 43 ms 3332 KB Output is correct
21 Correct 35 ms 3332 KB Output is correct
22 Correct 26 ms 3332 KB Output is correct
23 Correct 28 ms 3384 KB Output is correct
24 Correct 30 ms 3384 KB Output is correct
25 Correct 27 ms 3384 KB Output is correct
26 Correct 37 ms 3384 KB Output is correct
27 Correct 38 ms 3452 KB Output is correct
28 Correct 38 ms 3468 KB Output is correct
29 Correct 36 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 532 KB Output is correct
4 Correct 4 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 4 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 3 ms 832 KB Output is correct
10 Correct 3 ms 832 KB Output is correct
11 Correct 3 ms 832 KB Output is correct
12 Correct 3 ms 832 KB Output is correct
13 Correct 3 ms 832 KB Output is correct
14 Correct 13 ms 1416 KB Output is correct
15 Correct 19 ms 1936 KB Output is correct
16 Correct 27 ms 2308 KB Output is correct
17 Correct 36 ms 2688 KB Output is correct
18 Correct 35 ms 3332 KB Output is correct
19 Correct 36 ms 3332 KB Output is correct
20 Correct 43 ms 3332 KB Output is correct
21 Correct 35 ms 3332 KB Output is correct
22 Correct 26 ms 3332 KB Output is correct
23 Correct 28 ms 3384 KB Output is correct
24 Correct 30 ms 3384 KB Output is correct
25 Correct 27 ms 3384 KB Output is correct
26 Correct 37 ms 3384 KB Output is correct
27 Correct 38 ms 3452 KB Output is correct
28 Correct 38 ms 3468 KB Output is correct
29 Correct 36 ms 3468 KB Output is correct
30 Correct 77 ms 9052 KB Output is correct
31 Correct 108 ms 12336 KB Output is correct
32 Correct 126 ms 16560 KB Output is correct
33 Correct 264 ms 23236 KB Output is correct
34 Correct 79 ms 23676 KB Output is correct
35 Correct 189 ms 30856 KB Output is correct
36 Correct 183 ms 36692 KB Output is correct
37 Correct 185 ms 42516 KB Output is correct
38 Correct 186 ms 48420 KB Output is correct
39 Correct 195 ms 54264 KB Output is correct
40 Correct 176 ms 59872 KB Output is correct
41 Correct 201 ms 65708 KB Output is correct
42 Correct 223 ms 71416 KB Output is correct
43 Correct 193 ms 76552 KB Output is correct
44 Correct 158 ms 81836 KB Output is correct
45 Correct 168 ms 86896 KB Output is correct
46 Correct 154 ms 90916 KB Output is correct
47 Correct 173 ms 94552 KB Output is correct
48 Correct 214 ms 100540 KB Output is correct
49 Correct 207 ms 106376 KB Output is correct