답안 #967131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967131 2024-04-21T08:18:10 Z AlperenT_ 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
467 ms 62584 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long 
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5+10 + 10,  inf = 1e9+10 , mod = 1e9 + 7 ;
int a[maxn] , b[maxn] , u[maxn] ;
vector <int> cm ; 
vector <int> ch[maxn] ;
struct node{
    int mx , sm ;
    node(){
        mx = -inf ;sm = 0;
    }
};
node seg[12*maxn] ;

void bui(){
    int n = sz(cm) ;
    rep(i , 1 , 4*n){
        seg[i].mx = -inf ;
        seg[i].sm = 0 ;
    }
}

node operator+(node a, node b){
    node r ;
    r.sm = a.sm + b.sm ;
    r.mx = max(a.mx , b.mx) ;
    return r ;
}

void upd(int x , pii a , int p = 1, int l = 0, int r = sz(cm)-1){
    int mid = (l+r)/2 ,pl =p<<1,pr=p<<1|1;
    if(l > x || r < x)return ;
    if(l == r){
        seg[p].mx = max(seg[p].mx , a.F) ;
        seg[p].sm++;
        return ;
    }
    upd(x,a,pl,l,mid);
    upd(x,a,pr,mid+1,r);
    seg[p] = seg[pl] + seg[pr] ;
}
node que(int le ,int ri ,int p = 1 , int l = 0, int r =sz(cm)-1){
    int mid = (l+r)/2 ,pl =p<<1,pr=p<<1|1;
    if(le <= l && r <= ri)return seg[p] ;
    if(ri <= mid){
        return que(le,ri,pl,l,mid);
    }
    if(le > mid){
        return que(le,ri,pr,mid+1,r);
    }
    return que(le,ri,pl,l,mid) + que(le,ri,pr,mid+1,r) ;
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n , k ;
    cin >> n >> k ;
    rep(i ,1 ,n){
        cin >> a[i] >> b[i] ;
        cm.pb(a[i]) ;cm.pb(b[i]) ;
    }
    rep(i ,1 ,k){
        cin >> u[i] ;
        cm.pb(u[i]); 
    }
    sort(all(cm));
    cm.resize(unique(all(cm))-cm.begin()) ;
    rep(i ,1 , n){
        a[i] = lower_bound(all(cm) , a[i]) - cm.begin() ;
        b[i] = lower_bound(all(cm) , b[i]) - cm.begin() ;
    }
    rep(i , 1 , k){
        u[i] = lower_bound(all(cm) , u[i]) - cm.begin() ;
    }
    rep(i ,1 ,k){
        upd(u[i] , {i,0}); 
    }
    rep(i , 1, n){
        if(a[i] == b[i]){
            continue ;
        }
        int x = que(min(a[i] , b[i]) , max(a[i] , b[i])-1).mx ;
        if(x==-inf){
            x =0; 
        }else{
            if(a[i] < b[i])swap(a[i] , b[i]) ;
        }
        ch[x+1].pb(i) ;
    }
    bui();
    per(i , k+1 , 1){
        if(i!=k+1){
            upd(u[i] , {0 , 1});
        }
        for(int x : ch[i]){
            if(que(max(b[x],a[x]) , sz(cm)-1).sm %2==1){
                swap(a[x] , b[x]) ;
            }
        }
    }
    int ans =0;
    rep(i , 1,n){
        ans += cm[a[i]] ;
    }
    cout << ans << '\n'; 
    return 0 ;
}
/*


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45704 KB Output is correct
3 Correct 12 ms 45660 KB Output is correct
4 Correct 11 ms 45660 KB Output is correct
5 Correct 14 ms 45724 KB Output is correct
6 Correct 12 ms 45916 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 11 ms 45804 KB Output is correct
9 Correct 11 ms 45660 KB Output is correct
10 Correct 11 ms 45784 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 12 ms 45720 KB Output is correct
13 Correct 12 ms 45656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45704 KB Output is correct
3 Correct 12 ms 45660 KB Output is correct
4 Correct 11 ms 45660 KB Output is correct
5 Correct 14 ms 45724 KB Output is correct
6 Correct 12 ms 45916 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 11 ms 45804 KB Output is correct
9 Correct 11 ms 45660 KB Output is correct
10 Correct 11 ms 45784 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 12 ms 45720 KB Output is correct
13 Correct 12 ms 45656 KB Output is correct
14 Correct 24 ms 46424 KB Output is correct
15 Correct 40 ms 47072 KB Output is correct
16 Correct 56 ms 47836 KB Output is correct
17 Correct 72 ms 48592 KB Output is correct
18 Correct 81 ms 48588 KB Output is correct
19 Correct 74 ms 48532 KB Output is correct
20 Correct 72 ms 48520 KB Output is correct
21 Correct 71 ms 48844 KB Output is correct
22 Correct 58 ms 48120 KB Output is correct
23 Correct 55 ms 48112 KB Output is correct
24 Correct 54 ms 48076 KB Output is correct
25 Correct 58 ms 48332 KB Output is correct
26 Correct 64 ms 48092 KB Output is correct
27 Correct 67 ms 48588 KB Output is correct
28 Correct 60 ms 48596 KB Output is correct
29 Correct 67 ms 48600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45704 KB Output is correct
3 Correct 12 ms 45660 KB Output is correct
4 Correct 11 ms 45660 KB Output is correct
5 Correct 14 ms 45724 KB Output is correct
6 Correct 12 ms 45916 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 11 ms 45804 KB Output is correct
9 Correct 11 ms 45660 KB Output is correct
10 Correct 11 ms 45784 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 12 ms 45720 KB Output is correct
13 Correct 12 ms 45656 KB Output is correct
14 Correct 24 ms 46424 KB Output is correct
15 Correct 40 ms 47072 KB Output is correct
16 Correct 56 ms 47836 KB Output is correct
17 Correct 72 ms 48592 KB Output is correct
18 Correct 81 ms 48588 KB Output is correct
19 Correct 74 ms 48532 KB Output is correct
20 Correct 72 ms 48520 KB Output is correct
21 Correct 71 ms 48844 KB Output is correct
22 Correct 58 ms 48120 KB Output is correct
23 Correct 55 ms 48112 KB Output is correct
24 Correct 54 ms 48076 KB Output is correct
25 Correct 58 ms 48332 KB Output is correct
26 Correct 64 ms 48092 KB Output is correct
27 Correct 67 ms 48588 KB Output is correct
28 Correct 60 ms 48596 KB Output is correct
29 Correct 67 ms 48600 KB Output is correct
30 Correct 169 ms 49864 KB Output is correct
31 Correct 211 ms 54536 KB Output is correct
32 Correct 295 ms 54732 KB Output is correct
33 Correct 438 ms 62476 KB Output is correct
34 Correct 145 ms 49336 KB Output is correct
35 Correct 437 ms 62156 KB Output is correct
36 Correct 430 ms 62040 KB Output is correct
37 Correct 433 ms 62584 KB Output is correct
38 Correct 467 ms 61876 KB Output is correct
39 Correct 435 ms 61632 KB Output is correct
40 Correct 407 ms 61696 KB Output is correct
41 Correct 418 ms 61612 KB Output is correct
42 Correct 429 ms 62024 KB Output is correct
43 Correct 283 ms 62388 KB Output is correct
44 Correct 308 ms 61504 KB Output is correct
45 Correct 298 ms 61632 KB Output is correct
46 Correct 303 ms 59840 KB Output is correct
47 Correct 260 ms 59848 KB Output is correct
48 Correct 328 ms 62072 KB Output is correct
49 Correct 321 ms 61968 KB Output is correct