Submission #845994

# Submission time Handle Problem Language Result Execution time Memory
845994 2023-09-07T03:08:00 Z dungz Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
1193 ms 141560 KB
#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define task "task"
#define task "swapcard"
#define prll pair<ll,ll>
#define pb push_back
#define ld long double
#define int ll
const ll MIN=-1e18,MAX=1e18,MOD=1e9+7;
vector<int> f[800005];
int tree[3000005];
map<ll,int> danh;
int d=0;
pair<ll,ll> a[200005];
ll t[200005];
ll rev[1000005];
void build(ll node,ll l,ll r){
	if(l==r) {f[node].push_back(t[l]);return;}
	ll m=(l+r)/2;
	build(node*2,l,m);
	build(node*2+1,m+1,r);
	merge(f[node*2].begin(),f[node*2].end(),f[node*2+1].begin(),f[node*2+1].end(),back_inserter(f[node]));
}
ll chat(ll node,ll x){
	ll l=0,r=f[node].size()-1,fl=-1;
	while(l<=r){
		ll m=(l+r)/2;
		if(f[node][m]>=x){
			fl=m;
			r=m-1;
		}
		else l=m+1;
	}
	return (fl==-1?0:f[node].size()-fl);
}
ll get(ll node,ll l,ll r,ll u,ll v,ll x){
	if(l>v or r<u) return 0;
	if(l>=u and r<=v) return chat(node,x);
	ll m=(l+r)/2;
	return get(node*2,l,m,u,v,x)+get(node*2+1,m+1,r,u,v,x);
}
void update2(int node,int l,int r,int u,int v)
{
    if(l>u or r<u) return;
    if(l==r)
    {
        tree[node]=v;
        return;
    }
    int m=(l+r)/2;
    update2(node*2,l,m,u,v);
    update2(node*2+1,m+1,r,u,v);
    tree[node]=max(tree[node*2],tree[node*2+1]);
}
int get2(int node,int l ,int r ,int u, int v)
{
    if(l>v or r<u) return -1;
    if(l>=u and r<=v) return tree[node];
    int m=(l+r)/2;
    return max(get2(node*2,l,m,u,v),get2(node*2+1,m+1,r,u,v));
}
vector<ll> lst;
signed main(){
    
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].fi>>a[i].se;
        lst.push_back(a[i].fi);
        lst.push_back(a[i].se);
    }
    for(int i=1;i<=k;i++)
    {
        cin>>t[i];
        lst.push_back(t[i]);
    }
    sort(lst.begin(),lst.end());
    for(auto i:lst)
    {
        if(!danh[i])
        {
            danh[i]=++d;
            rev[d]=i;
        }
    }
    for(int i=1;i<=n;i++)
    {
        a[i].fi=danh[a[i].fi];
        a[i].se=danh[a[i].se];
    }
    for(int i=1;i<=4*d;i++)
    {
        tree[i]=-1;
    }
    for(int i=1;i<=k;i++)
    {
        t[i]=danh[t[i]];
        update2(1,1,d,t[i],i);
    }
    build(1,1,k);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        int u=a[i].fi,v=a[i].se;
        if(u>v) swap(u,v);
        int pos=get2(1,1,d,u,v-1);
//        cout<<u<<" "<<v<<" "<<pos<<endl;
        if(pos==-1)
        {
            int sl=get(1,1,k,1,k,v);
            if(sl%2==0) ans+=rev[a[i].fi];
            else ans+=rev[a[i].se];
//            if(sl%2==0) cout<<a[i].fi<<endl;
//            else cout<<a[i].se;
        }
        else
        {
            int sl=get(1,1,k,pos,k,v);
            if(sl%2==0) ans+=rev[v];
            else ans+=rev[u];
//            if(sl%2==0) cout<<u<<endl;
//            else cout<<u<<endl;
        }
//        cout<<endl;
    }
    cout<<ans;
}
/*

*/

Compilation message

fortune_telling2.cpp:9: warning: "task" redefined
    9 | #define task "swapcard"
      | 
fortune_telling2.cpp:8: note: this is the location of the previous definition
    8 | #define task "task"
      |
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26460 KB Output is correct
2 Correct 7 ms 26460 KB Output is correct
3 Correct 7 ms 26716 KB Output is correct
4 Correct 7 ms 26736 KB Output is correct
5 Correct 7 ms 26716 KB Output is correct
6 Correct 7 ms 26716 KB Output is correct
7 Correct 7 ms 26712 KB Output is correct
8 Correct 7 ms 26716 KB Output is correct
9 Correct 7 ms 26716 KB Output is correct
10 Correct 6 ms 26460 KB Output is correct
11 Correct 7 ms 26576 KB Output is correct
12 Correct 7 ms 26460 KB Output is correct
13 Correct 7 ms 26460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26460 KB Output is correct
2 Correct 7 ms 26460 KB Output is correct
3 Correct 7 ms 26716 KB Output is correct
4 Correct 7 ms 26736 KB Output is correct
5 Correct 7 ms 26716 KB Output is correct
6 Correct 7 ms 26716 KB Output is correct
7 Correct 7 ms 26712 KB Output is correct
8 Correct 7 ms 26716 KB Output is correct
9 Correct 7 ms 26716 KB Output is correct
10 Correct 6 ms 26460 KB Output is correct
11 Correct 7 ms 26576 KB Output is correct
12 Correct 7 ms 26460 KB Output is correct
13 Correct 7 ms 26460 KB Output is correct
14 Correct 29 ms 32640 KB Output is correct
15 Correct 60 ms 37324 KB Output is correct
16 Correct 86 ms 42284 KB Output is correct
17 Correct 125 ms 48080 KB Output is correct
18 Correct 124 ms 48068 KB Output is correct
19 Correct 120 ms 47908 KB Output is correct
20 Correct 123 ms 48104 KB Output is correct
21 Correct 120 ms 48072 KB Output is correct
22 Correct 90 ms 45520 KB Output is correct
23 Correct 85 ms 42192 KB Output is correct
24 Correct 81 ms 41264 KB Output is correct
25 Correct 96 ms 46244 KB Output is correct
26 Correct 91 ms 44960 KB Output is correct
27 Correct 105 ms 45520 KB Output is correct
28 Correct 99 ms 45864 KB Output is correct
29 Correct 113 ms 46772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26460 KB Output is correct
2 Correct 7 ms 26460 KB Output is correct
3 Correct 7 ms 26716 KB Output is correct
4 Correct 7 ms 26736 KB Output is correct
5 Correct 7 ms 26716 KB Output is correct
6 Correct 7 ms 26716 KB Output is correct
7 Correct 7 ms 26712 KB Output is correct
8 Correct 7 ms 26716 KB Output is correct
9 Correct 7 ms 26716 KB Output is correct
10 Correct 6 ms 26460 KB Output is correct
11 Correct 7 ms 26576 KB Output is correct
12 Correct 7 ms 26460 KB Output is correct
13 Correct 7 ms 26460 KB Output is correct
14 Correct 29 ms 32640 KB Output is correct
15 Correct 60 ms 37324 KB Output is correct
16 Correct 86 ms 42284 KB Output is correct
17 Correct 125 ms 48080 KB Output is correct
18 Correct 124 ms 48068 KB Output is correct
19 Correct 120 ms 47908 KB Output is correct
20 Correct 123 ms 48104 KB Output is correct
21 Correct 120 ms 48072 KB Output is correct
22 Correct 90 ms 45520 KB Output is correct
23 Correct 85 ms 42192 KB Output is correct
24 Correct 81 ms 41264 KB Output is correct
25 Correct 96 ms 46244 KB Output is correct
26 Correct 91 ms 44960 KB Output is correct
27 Correct 105 ms 45520 KB Output is correct
28 Correct 99 ms 45864 KB Output is correct
29 Correct 113 ms 46772 KB Output is correct
30 Correct 334 ms 94660 KB Output is correct
31 Correct 483 ms 104296 KB Output is correct
32 Correct 676 ms 118688 KB Output is correct
33 Correct 1093 ms 140728 KB Output is correct
34 Correct 303 ms 93132 KB Output is correct
35 Correct 1104 ms 139948 KB Output is correct
36 Correct 1144 ms 141496 KB Output is correct
37 Correct 1100 ms 141560 KB Output is correct
38 Correct 1078 ms 140692 KB Output is correct
39 Correct 1125 ms 140932 KB Output is correct
40 Correct 1032 ms 141100 KB Output is correct
41 Correct 1162 ms 141148 KB Output is correct
42 Correct 1193 ms 140280 KB Output is correct
43 Correct 650 ms 140692 KB Output is correct
44 Correct 645 ms 140752 KB Output is correct
45 Correct 626 ms 139880 KB Output is correct
46 Correct 552 ms 110256 KB Output is correct
47 Correct 464 ms 99056 KB Output is correct
48 Correct 787 ms 120324 KB Output is correct
49 Correct 731 ms 120816 KB Output is correct