답안 #1100921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100921 2024-10-15T03:33:02 Z sitablechair 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
423 ms 79808 KB
#include<bits/stdc++.h>
#define ll long long
#define sz(x) (signed)x.size()
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,l,r) for(int i=r;i>=l;i--)
#define F "CHOTMH"
#define fio freopen(F".inp","r",stdin);freopen(F".out","w",stdout);
using namespace std;

int n,k;

const int N=6e5+3;

struct BIT {
    int pf[N];
    void upd(int u,int val) {
        while(u<=k) {
            pf[u]=pf[u]+val;
            u+=u&(-u);
        }
    }
    int query(int u) {
        int ans=0;
        while(u>0) {
            ans+=pf[u];
            u-=u&(-u);
        }
        return ans;
    }
};
struct BITT {
    int pf[N];
    void upd(int u,int val) {
        while(u<=k) {
            pf[u]=min(pf[u],val);
            u+=u&(-u);
        }
    }
    int query(int u) {
        int ans=2e9;
        while(u>0) {
            ans=min(pf[u],ans);
            u-=u&(-u);
        }
        return ans;
    }
};
BIT bit;
BITT sus;
vector<int> in[N],sigma[N],sigma1[N],big;
pair<int,int> a[N];
bool huhu[N];
int q[N],pf[N],pp[N];
int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fio
    cin >> n >> k;
    ll ans=0;
    For(i,1,n) {
        cin >> a[i].ff >> a[i].ss;
        big.pb(a[i].ff);
        big.pb(a[i].ss);
    }
    For(i,1,k) {
        bit.pf[i]=0;
        sus.pf[i]=2e9;
        cin >> q[i];
        big.pb(q[i]);
        pf[i]=max(pf[i-1],q[i]);
    }
    sort(big.begin(),big.end());
    big.resize(unique(big.begin(),big.end())-big.begin());
    For(i,1,k) {
        int ind=lower_bound(big.begin(),big.end(),q[i])-big.begin();
        in[ind+1].pb(i);
    }
    For(i,1,n) {
        int ind=lower_bound(big.begin(),big.end(),a[i].ff)-big.begin();
        int ind1=lower_bound(big.begin(),big.end(),a[i].ss)-big.begin();
        if (a[i].ff!=a[i].ss) {
            sigma[min(ind,ind1)+1].pb(i);
            sigma1[max(ind,ind1)+1].pb(i);
        }
        else ans+=a[i].ff,huhu[i]=1;
    }
    ForD(i,1,sz(big)) {
        for(auto el: in[i]) sus.upd(k-el+1,q[el]);
        for(auto el: sigma[i]) {
            int l=(a[el].ff<a[el].ss?(lower_bound(pf+1,pf+1+k,a[el].ff)-pf)+1:1),r=k;
            int cc=l;
            if (l>k+1) {
                ans+=a[el].ff;
                huhu[el]=1;
            }
            if (a[el].ff<a[el].ss) swap(a[el].ff,a[el].ss);
            while(l<r) {
                int mid=l+(r-l+1)/2;
                if (sus.query(k-mid+1)<a[el].ff) l=mid;
                else r=mid-1;
            }
            if (sus.query(k-l+1)<a[el].ff) pp[el]=l;
            else pp[el]=cc;
        }
    }
    ForD(i,1,sz(big)) {
        for(auto el: in[i]) bit.upd(el,1);
        for(auto el: sigma1[i]) {
            if (huhu[el]) continue;
            int tm=bit.query(k)-bit.query(pp[el]-1);
            if (tm%2) ans+=a[el].ss;
            else ans+=a[el].ff;
        }
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 51792 KB Output is correct
2 Correct 10 ms 51792 KB Output is correct
3 Correct 10 ms 51792 KB Output is correct
4 Correct 9 ms 51656 KB Output is correct
5 Correct 9 ms 51792 KB Output is correct
6 Correct 9 ms 51792 KB Output is correct
7 Correct 9 ms 51792 KB Output is correct
8 Correct 9 ms 51792 KB Output is correct
9 Correct 8 ms 51792 KB Output is correct
10 Correct 8 ms 51792 KB Output is correct
11 Correct 8 ms 51696 KB Output is correct
12 Correct 9 ms 51788 KB Output is correct
13 Correct 9 ms 51672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 51792 KB Output is correct
2 Correct 10 ms 51792 KB Output is correct
3 Correct 10 ms 51792 KB Output is correct
4 Correct 9 ms 51656 KB Output is correct
5 Correct 9 ms 51792 KB Output is correct
6 Correct 9 ms 51792 KB Output is correct
7 Correct 9 ms 51792 KB Output is correct
8 Correct 9 ms 51792 KB Output is correct
9 Correct 8 ms 51792 KB Output is correct
10 Correct 8 ms 51792 KB Output is correct
11 Correct 8 ms 51696 KB Output is correct
12 Correct 9 ms 51788 KB Output is correct
13 Correct 9 ms 51672 KB Output is correct
14 Correct 18 ms 52816 KB Output is correct
15 Correct 30 ms 53972 KB Output is correct
16 Correct 45 ms 54932 KB Output is correct
17 Correct 56 ms 56264 KB Output is correct
18 Correct 59 ms 56108 KB Output is correct
19 Correct 59 ms 56264 KB Output is correct
20 Correct 63 ms 56264 KB Output is correct
21 Correct 53 ms 56220 KB Output is correct
22 Correct 44 ms 56012 KB Output is correct
23 Correct 40 ms 55764 KB Output is correct
24 Correct 39 ms 55752 KB Output is correct
25 Correct 40 ms 56016 KB Output is correct
26 Correct 44 ms 54720 KB Output is correct
27 Correct 49 ms 55248 KB Output is correct
28 Correct 52 ms 55004 KB Output is correct
29 Correct 58 ms 55596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 51792 KB Output is correct
2 Correct 10 ms 51792 KB Output is correct
3 Correct 10 ms 51792 KB Output is correct
4 Correct 9 ms 51656 KB Output is correct
5 Correct 9 ms 51792 KB Output is correct
6 Correct 9 ms 51792 KB Output is correct
7 Correct 9 ms 51792 KB Output is correct
8 Correct 9 ms 51792 KB Output is correct
9 Correct 8 ms 51792 KB Output is correct
10 Correct 8 ms 51792 KB Output is correct
11 Correct 8 ms 51696 KB Output is correct
12 Correct 9 ms 51788 KB Output is correct
13 Correct 9 ms 51672 KB Output is correct
14 Correct 18 ms 52816 KB Output is correct
15 Correct 30 ms 53972 KB Output is correct
16 Correct 45 ms 54932 KB Output is correct
17 Correct 56 ms 56264 KB Output is correct
18 Correct 59 ms 56108 KB Output is correct
19 Correct 59 ms 56264 KB Output is correct
20 Correct 63 ms 56264 KB Output is correct
21 Correct 53 ms 56220 KB Output is correct
22 Correct 44 ms 56012 KB Output is correct
23 Correct 40 ms 55764 KB Output is correct
24 Correct 39 ms 55752 KB Output is correct
25 Correct 40 ms 56016 KB Output is correct
26 Correct 44 ms 54720 KB Output is correct
27 Correct 49 ms 55248 KB Output is correct
28 Correct 52 ms 55004 KB Output is correct
29 Correct 58 ms 55596 KB Output is correct
30 Correct 116 ms 60356 KB Output is correct
31 Correct 171 ms 66108 KB Output is correct
32 Correct 245 ms 71336 KB Output is correct
33 Correct 357 ms 79716 KB Output is correct
34 Correct 102 ms 59460 KB Output is correct
35 Correct 423 ms 79800 KB Output is correct
36 Correct 394 ms 79800 KB Output is correct
37 Correct 391 ms 79808 KB Output is correct
38 Correct 407 ms 79788 KB Output is correct
39 Correct 403 ms 79696 KB Output is correct
40 Correct 335 ms 79712 KB Output is correct
41 Correct 354 ms 79800 KB Output is correct
42 Correct 419 ms 79796 KB Output is correct
43 Correct 212 ms 79800 KB Output is correct
44 Correct 211 ms 79616 KB Output is correct
45 Correct 210 ms 79804 KB Output is correct
46 Correct 200 ms 78096 KB Output is correct
47 Correct 192 ms 77496 KB Output is correct
48 Correct 250 ms 74260 KB Output is correct
49 Correct 243 ms 74284 KB Output is correct