Submission #1112556

# Submission time Handle Problem Language Result Execution time Memory
1112556 2024-11-14T10:21:46 Z Pioneer New Home (APIO18_new_home) C++17
57 / 100
5000 ms 330824 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
// #pragma GCC target("avx2")

#define ll long long
// #define int ll
#define all(v) v.begin(),v.end()
#define sz(s) ((int)s.size())
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound

using namespace std;

const int inf=1e8;
const int MAX=3e5+10;
const int mod=1e9+7;

int binpow(int a,int n){
    if(!n)return 1;
    if(n%2==1)return a*binpow(a,n-1)%mod;
    int k=binpow(a,n/2);
    return k*k%mod;
}

int n,k,q,m;
int a[MAX],b[MAX],x[MAX],t[MAX];
int l[MAX],y[MAX];
vector<int> events[MAX+MAX],zap[MAX+MAX];
multiset<int> st[MAX];
vector<int> tim,pos;

struct segtree{
    multiset<int> t[4*3*MAX];
    int mx[4*3*MAX];
    int cnt=1;

    segtree(){
        memset(mx,-1,sizeof(mx));
    }

    void add(int v,int tl,int tr,int pos,int x){
        if(tl==tr){
            t[v].insert(x);
            mx[v]=*t[v].rbegin();
            return;
        }
        int tm=(tl+tr)/2;
        if(pos<=tm){
            add(2*v,tl,tm,pos,x);
        }
        else{
            add(2*v+1,tm+1,tr,pos,x);
        }
        mx[v]=max(mx[2*v],mx[2*v+1]);
    }

    void del(int v,int tl,int tr,int pos,int x){
        if(tl==tr){
            t[v].erase(t[v].find(x));
            if(t[v].empty())mx[v]=-1;
            else mx[v]=*t[v].rbegin();
            return;
        }
        int tm=(tl+tr)/2;
        if(pos<=tm){
            del(2*v,tl,tm,pos,x);
        }
        else{
            del(2*v+1,tm+1,tr,pos,x);
        }
        mx[v]=max(mx[2*v],mx[2*v+1]);
    }

    int get(int v,int tl,int tr,int l,int r){
        if(l>r||tl>r||l>tr)return 0;
        if(l<=tl&&tr<=r)return mx[v];
        int tm=(tl+tr)/2;
        return max(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
    }
}tree;

int L[MAX],R[MAX];
int cnt[MAX],col;

int getx(int x){
    return lb(all(pos),x)-pos.begin();
}

void add(int id){
    if(cnt[t[id]]==0)col++;
    cnt[t[id]]++;
    if(st[t[id]].count(x[id]))st[t[id]].insert(x[id]);
    else{
        auto l=--st[t[id]].lb(x[id]);
        auto r=st[t[id]].lb(x[id]);
        int LL=getx(*l+1);
        if(!(*l==-1&&*r==inf+1))tree.del(1,0,m-1,LL,*r-1);
        tree.add(1,0,m-1,LL,x[id]-1);
        tree.add(1,0,m-1,getx(x[id]+1),*r-1);
        st[t[id]].insert(x[id]);
    }
}

void del(int id){
    id=-id;
    cnt[t[id]]--;
    if(cnt[t[id]]==0)col--;
    st[t[id]].erase(st[t[id]].find(x[id]));
    if(!st[t[id]].count(x[id])){
        auto l=--st[t[id]].lb(x[id]);
        auto r=st[t[id]].lb(x[id]);
        int LL=getx(*l+1);
        tree.del(1,0,m-1,LL,x[id]-1);
        tree.del(1,0,m-1,getx(x[id]+1),*r-1);
        if(!(*l==-1&&*r==inf+1))tree.add(1,0,m-1,LL,*r-1);
    }
}

bool check(int l,int r){
    l=max(l,0);
    r=min(r,inf);
    l=ub(all(pos),l)-pos.begin()-1;
    if(tree.get(1,0,m-1,0,l)>=r)return 0;
    return 1;
}

int ans[MAX];

void solve(){
    cin>>n>>k>>q;
    pos.pb(0),pos.pb(inf);
    for(int i=1;i<=n;i++){
        cin>>x[i]>>t[i]>>a[i]>>b[i];
        tim.pb(a[i]);
        tim.pb(b[i]+1);
        pos.pb(x[i]+1);
        pos.pb(x[i]-1);
    }
    for(int i=1;i<=q;i++){
        cin>>l[i]>>y[i];
        tim.pb(y[i]);
    }
    sort(all(tim));
    tim.erase(unique(all(tim)),tim.end());
    sort(all(pos));
    pos.erase(unique(all(pos)),pos.end());
    for(int i=1;i<=n;i++){
        a[i]=lb(all(tim),a[i])-tim.begin();
        b[i]=lb(all(tim),b[i]+1)-tim.begin();
        events[a[i]].pb(i);
        events[b[i]].pb(-i);
    }
    for(int i=1;i<=q;i++){
        y[i]=lb(all(tim),y[i])-tim.begin();
        zap[y[i]].pb(i);
    }
    for(int i=1;i<=k;i++){
        st[i].insert(-1);
        st[i].insert(inf+1);
    }
    m=sz(pos);
    for(int i=0;i<sz(tim);i++){
        for(auto id:events[i]){
            if(id>0){
                add(id);
            }
            else{
                del(id);
            }
        }
        for(int id:zap[i]){
            if(col!=k){
                ans[id]=-1;
            }
            else{
                int L=0,R=inf,res=inf;
                while(L<=R){
                    int mid=(L+R)/2;
                    if(check(l[id]-mid,l[id]+mid)){
                        R=mid-1,res=mid;
                    }
                    else L=mid+1;
                }
                ans[id]=res;
            }
        }
    }
    for(int i=1;i<=q;i++)cout<<ans[i]<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 96 ms 228168 KB Output is correct
2 Correct 94 ms 228184 KB Output is correct
3 Correct 94 ms 228168 KB Output is correct
4 Correct 99 ms 228140 KB Output is correct
5 Correct 102 ms 228072 KB Output is correct
6 Correct 103 ms 228172 KB Output is correct
7 Correct 112 ms 228360 KB Output is correct
8 Correct 102 ms 228288 KB Output is correct
9 Correct 116 ms 228168 KB Output is correct
10 Correct 106 ms 228168 KB Output is correct
11 Correct 105 ms 228168 KB Output is correct
12 Correct 114 ms 228176 KB Output is correct
13 Correct 108 ms 228168 KB Output is correct
14 Correct 110 ms 228200 KB Output is correct
15 Correct 116 ms 228348 KB Output is correct
16 Correct 120 ms 228168 KB Output is correct
17 Correct 122 ms 228152 KB Output is correct
18 Correct 117 ms 228168 KB Output is correct
19 Correct 129 ms 228344 KB Output is correct
20 Correct 119 ms 228168 KB Output is correct
21 Correct 110 ms 228192 KB Output is correct
22 Correct 116 ms 228236 KB Output is correct
23 Correct 119 ms 228196 KB Output is correct
24 Correct 115 ms 228168 KB Output is correct
25 Correct 114 ms 228172 KB Output is correct
26 Correct 118 ms 228168 KB Output is correct
27 Correct 124 ms 228296 KB Output is correct
28 Correct 110 ms 228168 KB Output is correct
29 Correct 111 ms 228172 KB Output is correct
30 Correct 113 ms 228168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 228168 KB Output is correct
2 Correct 94 ms 228184 KB Output is correct
3 Correct 94 ms 228168 KB Output is correct
4 Correct 99 ms 228140 KB Output is correct
5 Correct 102 ms 228072 KB Output is correct
6 Correct 103 ms 228172 KB Output is correct
7 Correct 112 ms 228360 KB Output is correct
8 Correct 102 ms 228288 KB Output is correct
9 Correct 116 ms 228168 KB Output is correct
10 Correct 106 ms 228168 KB Output is correct
11 Correct 105 ms 228168 KB Output is correct
12 Correct 114 ms 228176 KB Output is correct
13 Correct 108 ms 228168 KB Output is correct
14 Correct 110 ms 228200 KB Output is correct
15 Correct 116 ms 228348 KB Output is correct
16 Correct 120 ms 228168 KB Output is correct
17 Correct 122 ms 228152 KB Output is correct
18 Correct 117 ms 228168 KB Output is correct
19 Correct 129 ms 228344 KB Output is correct
20 Correct 119 ms 228168 KB Output is correct
21 Correct 110 ms 228192 KB Output is correct
22 Correct 116 ms 228236 KB Output is correct
23 Correct 119 ms 228196 KB Output is correct
24 Correct 115 ms 228168 KB Output is correct
25 Correct 114 ms 228172 KB Output is correct
26 Correct 118 ms 228168 KB Output is correct
27 Correct 124 ms 228296 KB Output is correct
28 Correct 110 ms 228168 KB Output is correct
29 Correct 111 ms 228172 KB Output is correct
30 Correct 113 ms 228168 KB Output is correct
31 Correct 593 ms 242256 KB Output is correct
32 Correct 497 ms 232632 KB Output is correct
33 Correct 640 ms 238524 KB Output is correct
34 Correct 588 ms 238772 KB Output is correct
35 Correct 624 ms 243688 KB Output is correct
36 Correct 589 ms 242084 KB Output is correct
37 Correct 519 ms 236904 KB Output is correct
38 Correct 525 ms 236984 KB Output is correct
39 Correct 464 ms 236472 KB Output is correct
40 Correct 458 ms 236480 KB Output is correct
41 Correct 434 ms 236820 KB Output is correct
42 Correct 362 ms 236472 KB Output is correct
43 Correct 199 ms 235448 KB Output is correct
44 Correct 435 ms 236976 KB Output is correct
45 Correct 434 ms 236716 KB Output is correct
46 Correct 464 ms 236632 KB Output is correct
47 Correct 318 ms 236092 KB Output is correct
48 Correct 341 ms 236228 KB Output is correct
49 Correct 398 ms 236216 KB Output is correct
50 Correct 348 ms 236480 KB Output is correct
51 Correct 388 ms 236292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2373 ms 292928 KB Output is correct
2 Correct 3306 ms 282520 KB Output is correct
3 Correct 2407 ms 327236 KB Output is correct
4 Correct 2421 ms 298324 KB Output is correct
5 Correct 3365 ms 282232 KB Output is correct
6 Correct 3397 ms 286620 KB Output is correct
7 Correct 2039 ms 330824 KB Output is correct
8 Correct 2017 ms 298296 KB Output is correct
9 Correct 2082 ms 288184 KB Output is correct
10 Correct 2713 ms 283324 KB Output is correct
11 Correct 2043 ms 282008 KB Output is correct
12 Correct 2071 ms 283008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3022 ms 291732 KB Output is correct
2 Execution timed out 5040 ms 254676 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 228168 KB Output is correct
2 Correct 94 ms 228184 KB Output is correct
3 Correct 94 ms 228168 KB Output is correct
4 Correct 99 ms 228140 KB Output is correct
5 Correct 102 ms 228072 KB Output is correct
6 Correct 103 ms 228172 KB Output is correct
7 Correct 112 ms 228360 KB Output is correct
8 Correct 102 ms 228288 KB Output is correct
9 Correct 116 ms 228168 KB Output is correct
10 Correct 106 ms 228168 KB Output is correct
11 Correct 105 ms 228168 KB Output is correct
12 Correct 114 ms 228176 KB Output is correct
13 Correct 108 ms 228168 KB Output is correct
14 Correct 110 ms 228200 KB Output is correct
15 Correct 116 ms 228348 KB Output is correct
16 Correct 120 ms 228168 KB Output is correct
17 Correct 122 ms 228152 KB Output is correct
18 Correct 117 ms 228168 KB Output is correct
19 Correct 129 ms 228344 KB Output is correct
20 Correct 119 ms 228168 KB Output is correct
21 Correct 110 ms 228192 KB Output is correct
22 Correct 116 ms 228236 KB Output is correct
23 Correct 119 ms 228196 KB Output is correct
24 Correct 115 ms 228168 KB Output is correct
25 Correct 114 ms 228172 KB Output is correct
26 Correct 118 ms 228168 KB Output is correct
27 Correct 124 ms 228296 KB Output is correct
28 Correct 110 ms 228168 KB Output is correct
29 Correct 111 ms 228172 KB Output is correct
30 Correct 113 ms 228168 KB Output is correct
31 Correct 593 ms 242256 KB Output is correct
32 Correct 497 ms 232632 KB Output is correct
33 Correct 640 ms 238524 KB Output is correct
34 Correct 588 ms 238772 KB Output is correct
35 Correct 624 ms 243688 KB Output is correct
36 Correct 589 ms 242084 KB Output is correct
37 Correct 519 ms 236904 KB Output is correct
38 Correct 525 ms 236984 KB Output is correct
39 Correct 464 ms 236472 KB Output is correct
40 Correct 458 ms 236480 KB Output is correct
41 Correct 434 ms 236820 KB Output is correct
42 Correct 362 ms 236472 KB Output is correct
43 Correct 199 ms 235448 KB Output is correct
44 Correct 435 ms 236976 KB Output is correct
45 Correct 434 ms 236716 KB Output is correct
46 Correct 464 ms 236632 KB Output is correct
47 Correct 318 ms 236092 KB Output is correct
48 Correct 341 ms 236228 KB Output is correct
49 Correct 398 ms 236216 KB Output is correct
50 Correct 348 ms 236480 KB Output is correct
51 Correct 388 ms 236292 KB Output is correct
52 Correct 353 ms 251064 KB Output is correct
53 Correct 325 ms 246716 KB Output is correct
54 Correct 373 ms 244928 KB Output is correct
55 Correct 465 ms 243008 KB Output is correct
56 Correct 457 ms 243896 KB Output is correct
57 Correct 471 ms 238264 KB Output is correct
58 Correct 391 ms 241336 KB Output is correct
59 Correct 407 ms 243640 KB Output is correct
60 Correct 387 ms 238008 KB Output is correct
61 Correct 195 ms 247484 KB Output is correct
62 Correct 384 ms 250836 KB Output is correct
63 Correct 438 ms 246400 KB Output is correct
64 Correct 410 ms 243128 KB Output is correct
65 Correct 448 ms 239800 KB Output is correct
66 Correct 431 ms 236728 KB Output is correct
67 Correct 247 ms 233912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 228168 KB Output is correct
2 Correct 94 ms 228184 KB Output is correct
3 Correct 94 ms 228168 KB Output is correct
4 Correct 99 ms 228140 KB Output is correct
5 Correct 102 ms 228072 KB Output is correct
6 Correct 103 ms 228172 KB Output is correct
7 Correct 112 ms 228360 KB Output is correct
8 Correct 102 ms 228288 KB Output is correct
9 Correct 116 ms 228168 KB Output is correct
10 Correct 106 ms 228168 KB Output is correct
11 Correct 105 ms 228168 KB Output is correct
12 Correct 114 ms 228176 KB Output is correct
13 Correct 108 ms 228168 KB Output is correct
14 Correct 110 ms 228200 KB Output is correct
15 Correct 116 ms 228348 KB Output is correct
16 Correct 120 ms 228168 KB Output is correct
17 Correct 122 ms 228152 KB Output is correct
18 Correct 117 ms 228168 KB Output is correct
19 Correct 129 ms 228344 KB Output is correct
20 Correct 119 ms 228168 KB Output is correct
21 Correct 110 ms 228192 KB Output is correct
22 Correct 116 ms 228236 KB Output is correct
23 Correct 119 ms 228196 KB Output is correct
24 Correct 115 ms 228168 KB Output is correct
25 Correct 114 ms 228172 KB Output is correct
26 Correct 118 ms 228168 KB Output is correct
27 Correct 124 ms 228296 KB Output is correct
28 Correct 110 ms 228168 KB Output is correct
29 Correct 111 ms 228172 KB Output is correct
30 Correct 113 ms 228168 KB Output is correct
31 Correct 593 ms 242256 KB Output is correct
32 Correct 497 ms 232632 KB Output is correct
33 Correct 640 ms 238524 KB Output is correct
34 Correct 588 ms 238772 KB Output is correct
35 Correct 624 ms 243688 KB Output is correct
36 Correct 589 ms 242084 KB Output is correct
37 Correct 519 ms 236904 KB Output is correct
38 Correct 525 ms 236984 KB Output is correct
39 Correct 464 ms 236472 KB Output is correct
40 Correct 458 ms 236480 KB Output is correct
41 Correct 434 ms 236820 KB Output is correct
42 Correct 362 ms 236472 KB Output is correct
43 Correct 199 ms 235448 KB Output is correct
44 Correct 435 ms 236976 KB Output is correct
45 Correct 434 ms 236716 KB Output is correct
46 Correct 464 ms 236632 KB Output is correct
47 Correct 318 ms 236092 KB Output is correct
48 Correct 341 ms 236228 KB Output is correct
49 Correct 398 ms 236216 KB Output is correct
50 Correct 348 ms 236480 KB Output is correct
51 Correct 388 ms 236292 KB Output is correct
52 Correct 2373 ms 292928 KB Output is correct
53 Correct 3306 ms 282520 KB Output is correct
54 Correct 2407 ms 327236 KB Output is correct
55 Correct 2421 ms 298324 KB Output is correct
56 Correct 3365 ms 282232 KB Output is correct
57 Correct 3397 ms 286620 KB Output is correct
58 Correct 2039 ms 330824 KB Output is correct
59 Correct 2017 ms 298296 KB Output is correct
60 Correct 2082 ms 288184 KB Output is correct
61 Correct 2713 ms 283324 KB Output is correct
62 Correct 2043 ms 282008 KB Output is correct
63 Correct 2071 ms 283008 KB Output is correct
64 Correct 3022 ms 291732 KB Output is correct
65 Execution timed out 5040 ms 254676 KB Time limit exceeded
66 Halted 0 ms 0 KB -