답안 #317578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317578 2020-10-30T02:47:21 Z BJoozz 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
981 ms 51732 KB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
using ll = long long ;
//#define int long long

using ii = pair < int , int > ;
const int MAX = 200004,M=600004,mod=1e9+7;
const int inf=0x3f3f3f3f;
int K;
vector < int > pr[MAX];
ii a[MAX];
void maxx(int &a,int b){
if(b>a) a=b;
}

int t[MAX];
int F[M];
int val[M];
void upd(int id,int val){
    for(;id<M;id+=id&-id) maxx(F[id],val);
}
int get(int id){
    int res=0;;
    for(;id>0;id-=id&-id) maxx(res,F[id]);
    return res;
}
bool ok[MAX];
ii b[MAX];
void UPD(int id){
    for(;id>0;id-=id&-id)F[id]++;
}
int GET(int id){
    int res=0;
    for(;id<M;id+=id&-id)res+=F[id];
    return res;
}
bool cmp(ii u,ii v){
    return min(u.X,u.Y)>min(v.X,v.Y);
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("fortune.inp", "r", stdin);//freopen("fortune.out", "w", stdout);
    int n,m;
    cin>>n>>m;
    ll ans=0;
    vector < int > vec;
    map < int , int > mp;
    for(int i=1;i<=n;i++){
        cin>>a[i].X>>a[i].Y;
        if(a[i].X==a[i].Y) {ans+=a[i].X;i--;n--;continue;}
        vec.pb(a[i].X);
        vec.pb(a[i].Y);
    }
    for(int i=1;i<=m;i++){
        cin>>t[i];
        vec.pb(t[i]);
    }
    sort(vec.begin(),vec.end());
    int pre=0,cnt=0;

    for(int u:vec)if(u!=pre){
        val[++cnt]=u;
        mp[u]=cnt;
        pre=u;
    }
    //cout<<n<<'\n';
    for(int i=1;i<=n;i++){
        a[i].X=mp[a[i].X];
        a[i].Y=mp[a[i].Y];
    }
    for(int i=1;i<=m;i++){
        t[i]=mp[t[i]];
        //cout<<t[i]<<'\n';
        b[i]=ii(t[i],i);
    }
    sort(b+1,b+1+m,greater < ii > () );
    sort(a+1,a+1+n,cmp );
    for(int i=1,x,po=1;i<=n;i++){
        bool tt=0;
        if(a[i].X>a[i].Y) {swap(a[i].X,a[i].Y);ok[i]=1;}
        while(b[po].X>=a[i].X) {
            upd(b[po].X,b[po].Y);po++;
        }
        x=get(a[i].Y-1);
        pr[x].pb(i);
        //cout<<a[i].X<<' '<<a[i].Y<<' '<<t[x]<<' '<<x<<'\n';
        //if(tt)swap(a[i].X,a[i].Y);
    }
    memset(F,0,sizeof F);
    for(int i=m,x;i>0;i--){
        for(int u:pr[i]){
            x=GET(a[u].Y);
            //cout<<val[a[u].X]<<' '<<val[a[u].Y]<<' '<<x<<'\n';
            if(x&1) ans+=val[a[u].X];
            else ans+=val[a[u].Y];
        }
        UPD(t[i]);
    }

    for(int u:pr[0]){
        int x=GET(a[u].Y)^ok[u]^1;
        //cout<<val[a[u].X]<<' '<<val[a[u].Y]<<' '<<x<<'\n';
        if(x&1) ans+=val[a[u].X];
        else ans+=val[a[u].Y];
    }
    cout<<ans;


}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:82:14: warning: unused variable 'tt' [-Wunused-variable]
   82 |         bool tt=0;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7552 KB Output is correct
2 Correct 7 ms 7552 KB Output is correct
3 Correct 7 ms 7680 KB Output is correct
4 Correct 7 ms 7680 KB Output is correct
5 Correct 7 ms 7696 KB Output is correct
6 Correct 7 ms 7680 KB Output is correct
7 Correct 7 ms 7680 KB Output is correct
8 Correct 7 ms 7680 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 6 ms 7552 KB Output is correct
11 Correct 7 ms 7552 KB Output is correct
12 Correct 7 ms 7552 KB Output is correct
13 Correct 7 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7552 KB Output is correct
2 Correct 7 ms 7552 KB Output is correct
3 Correct 7 ms 7680 KB Output is correct
4 Correct 7 ms 7680 KB Output is correct
5 Correct 7 ms 7696 KB Output is correct
6 Correct 7 ms 7680 KB Output is correct
7 Correct 7 ms 7680 KB Output is correct
8 Correct 7 ms 7680 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 6 ms 7552 KB Output is correct
11 Correct 7 ms 7552 KB Output is correct
12 Correct 7 ms 7552 KB Output is correct
13 Correct 7 ms 7552 KB Output is correct
14 Correct 26 ms 9592 KB Output is correct
15 Correct 51 ms 11768 KB Output is correct
16 Correct 79 ms 13992 KB Output is correct
17 Correct 113 ms 16244 KB Output is correct
18 Correct 115 ms 16368 KB Output is correct
19 Correct 118 ms 16372 KB Output is correct
20 Correct 113 ms 16264 KB Output is correct
21 Correct 108 ms 16368 KB Output is correct
22 Correct 72 ms 13816 KB Output is correct
23 Correct 65 ms 12660 KB Output is correct
24 Correct 60 ms 12020 KB Output is correct
25 Correct 77 ms 14480 KB Output is correct
26 Correct 73 ms 13556 KB Output is correct
27 Correct 90 ms 14324 KB Output is correct
28 Correct 77 ms 14196 KB Output is correct
29 Correct 102 ms 15344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7552 KB Output is correct
2 Correct 7 ms 7552 KB Output is correct
3 Correct 7 ms 7680 KB Output is correct
4 Correct 7 ms 7680 KB Output is correct
5 Correct 7 ms 7696 KB Output is correct
6 Correct 7 ms 7680 KB Output is correct
7 Correct 7 ms 7680 KB Output is correct
8 Correct 7 ms 7680 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 6 ms 7552 KB Output is correct
11 Correct 7 ms 7552 KB Output is correct
12 Correct 7 ms 7552 KB Output is correct
13 Correct 7 ms 7552 KB Output is correct
14 Correct 26 ms 9592 KB Output is correct
15 Correct 51 ms 11768 KB Output is correct
16 Correct 79 ms 13992 KB Output is correct
17 Correct 113 ms 16244 KB Output is correct
18 Correct 115 ms 16368 KB Output is correct
19 Correct 118 ms 16372 KB Output is correct
20 Correct 113 ms 16264 KB Output is correct
21 Correct 108 ms 16368 KB Output is correct
22 Correct 72 ms 13816 KB Output is correct
23 Correct 65 ms 12660 KB Output is correct
24 Correct 60 ms 12020 KB Output is correct
25 Correct 77 ms 14480 KB Output is correct
26 Correct 73 ms 13556 KB Output is correct
27 Correct 90 ms 14324 KB Output is correct
28 Correct 77 ms 14196 KB Output is correct
29 Correct 102 ms 15344 KB Output is correct
30 Correct 265 ms 24048 KB Output is correct
31 Correct 387 ms 30056 KB Output is correct
32 Correct 577 ms 36968 KB Output is correct
33 Correct 981 ms 51296 KB Output is correct
34 Correct 227 ms 22768 KB Output is correct
35 Correct 961 ms 51424 KB Output is correct
36 Correct 974 ms 51556 KB Output is correct
37 Correct 956 ms 51424 KB Output is correct
38 Correct 964 ms 51424 KB Output is correct
39 Correct 942 ms 51272 KB Output is correct
40 Correct 829 ms 51732 KB Output is correct
41 Correct 940 ms 51132 KB Output is correct
42 Correct 965 ms 51168 KB Output is correct
43 Correct 520 ms 51168 KB Output is correct
44 Correct 490 ms 51040 KB Output is correct
45 Correct 495 ms 51060 KB Output is correct
46 Correct 430 ms 34144 KB Output is correct
47 Correct 365 ms 28632 KB Output is correct
48 Correct 585 ms 41316 KB Output is correct
49 Correct 553 ms 41388 KB Output is correct