답안 #1100922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100922 2024-10-15T03:33:20 Z vjudge1 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
403 ms 79804 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 8 ms 51792 KB Output is correct
2 Correct 9 ms 51792 KB Output is correct
3 Correct 9 ms 51792 KB Output is correct
4 Correct 9 ms 51792 KB Output is correct
5 Correct 9 ms 51896 KB Output is correct
6 Correct 9 ms 51960 KB Output is correct
7 Correct 9 ms 51792 KB Output is correct
8 Correct 9 ms 51792 KB Output is correct
9 Correct 9 ms 51688 KB Output is correct
10 Correct 9 ms 51792 KB Output is correct
11 Correct 9 ms 51672 KB Output is correct
12 Correct 9 ms 51640 KB Output is correct
13 Correct 9 ms 51960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 51792 KB Output is correct
2 Correct 9 ms 51792 KB Output is correct
3 Correct 9 ms 51792 KB Output is correct
4 Correct 9 ms 51792 KB Output is correct
5 Correct 9 ms 51896 KB Output is correct
6 Correct 9 ms 51960 KB Output is correct
7 Correct 9 ms 51792 KB Output is correct
8 Correct 9 ms 51792 KB Output is correct
9 Correct 9 ms 51688 KB Output is correct
10 Correct 9 ms 51792 KB Output is correct
11 Correct 9 ms 51672 KB Output is correct
12 Correct 9 ms 51640 KB Output is correct
13 Correct 9 ms 51960 KB Output is correct
14 Correct 20 ms 52820 KB Output is correct
15 Correct 31 ms 53972 KB Output is correct
16 Correct 48 ms 54992 KB Output is correct
17 Correct 61 ms 56272 KB Output is correct
18 Correct 57 ms 56264 KB Output is correct
19 Correct 55 ms 56268 KB Output is correct
20 Correct 58 ms 56264 KB Output is correct
21 Correct 55 ms 56272 KB Output is correct
22 Correct 45 ms 56016 KB Output is correct
23 Correct 40 ms 55752 KB Output is correct
24 Correct 39 ms 55760 KB Output is correct
25 Correct 44 ms 56008 KB Output is correct
26 Correct 47 ms 54748 KB Output is correct
27 Correct 52 ms 55240 KB Output is correct
28 Correct 49 ms 55096 KB Output is correct
29 Correct 62 ms 55496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 51792 KB Output is correct
2 Correct 9 ms 51792 KB Output is correct
3 Correct 9 ms 51792 KB Output is correct
4 Correct 9 ms 51792 KB Output is correct
5 Correct 9 ms 51896 KB Output is correct
6 Correct 9 ms 51960 KB Output is correct
7 Correct 9 ms 51792 KB Output is correct
8 Correct 9 ms 51792 KB Output is correct
9 Correct 9 ms 51688 KB Output is correct
10 Correct 9 ms 51792 KB Output is correct
11 Correct 9 ms 51672 KB Output is correct
12 Correct 9 ms 51640 KB Output is correct
13 Correct 9 ms 51960 KB Output is correct
14 Correct 20 ms 52820 KB Output is correct
15 Correct 31 ms 53972 KB Output is correct
16 Correct 48 ms 54992 KB Output is correct
17 Correct 61 ms 56272 KB Output is correct
18 Correct 57 ms 56264 KB Output is correct
19 Correct 55 ms 56268 KB Output is correct
20 Correct 58 ms 56264 KB Output is correct
21 Correct 55 ms 56272 KB Output is correct
22 Correct 45 ms 56016 KB Output is correct
23 Correct 40 ms 55752 KB Output is correct
24 Correct 39 ms 55760 KB Output is correct
25 Correct 44 ms 56008 KB Output is correct
26 Correct 47 ms 54748 KB Output is correct
27 Correct 52 ms 55240 KB Output is correct
28 Correct 49 ms 55096 KB Output is correct
29 Correct 62 ms 55496 KB Output is correct
30 Correct 117 ms 60356 KB Output is correct
31 Correct 169 ms 66240 KB Output is correct
32 Correct 246 ms 71360 KB Output is correct
33 Correct 372 ms 79800 KB Output is correct
34 Correct 98 ms 59588 KB Output is correct
35 Correct 361 ms 79656 KB Output is correct
36 Correct 403 ms 79800 KB Output is correct
37 Correct 386 ms 79804 KB Output is correct
38 Correct 381 ms 79800 KB Output is correct
39 Correct 350 ms 79784 KB Output is correct
40 Correct 328 ms 79544 KB Output is correct
41 Correct 372 ms 79800 KB Output is correct
42 Correct 379 ms 79804 KB Output is correct
43 Correct 226 ms 79636 KB Output is correct
44 Correct 200 ms 79800 KB Output is correct
45 Correct 193 ms 79800 KB Output is correct
46 Correct 202 ms 78008 KB Output is correct
47 Correct 190 ms 77504 KB Output is correct
48 Correct 253 ms 74424 KB Output is correct
49 Correct 243 ms 74168 KB Output is correct