답안 #1112594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112594 2024-11-14T11:32:26 Z Pioneer 새 집 (APIO18_new_home) C++17
57 / 100
5000 ms 218760 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("Ofast")
 
#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+MAX],zap[MAX+MAX+MAX];
multiset<int> st[MAX];
vector<int> tim,pos;
 
struct segtree{
    multiset<int> t[2*2*MAX];
    int mx[2*2*MAX];
 
    segtree(){
        memset(mx,-1,sizeof(mx));
    }
 
    void add(int v,int tl,int tr,int pos,int x){
        pos+=m;
        t[pos].insert(x);
        mx[pos]=*t[pos].rbegin();
        while(pos>1){
            pos/=2;
            mx[pos]=max(mx[2*pos],mx[2*pos+1]);
        }
    }
 
    void del(int v,int tl,int tr,int pos,int x){
        pos+=m;
        t[pos].erase(t[pos].find(x));
        mx[pos]=(t[pos].empty()?-1:*t[pos].rbegin());
        while(pos>1){
            pos/=2;
            mx[pos]=max(mx[2*pos],mx[2*pos+1]);
        }
    }
 
    int get(int v,int tl,int tr,int l,int r){
        l+=m,r+=m+1;
        int res=0;
        while(l<r){
            if(l&1){
                res=max(res,mx[l++]);
            }
            if(r&1){
                res=max(res,mx[--r]);
            }
            l/=2,r/=2;
        }
        return res;
    }
}tree;
 
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;
    // cout<<0<<" "<<l<<" "<<tree.get(1,0,m-1,0,l)<<"\n";
    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++){
        // cerr<<i<<"\n";
        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;
    // int init=clock();
    while(t--)solve();
    // #ifdef LOCAL
    //     cout<<1.0*(clock()-init)/CLOCKS_PER_SEC<<"s\n";
    // #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 119376 KB Output is correct
2 Correct 25 ms 119384 KB Output is correct
3 Correct 19 ms 119376 KB Output is correct
4 Correct 24 ms 119544 KB Output is correct
5 Correct 31 ms 119376 KB Output is correct
6 Correct 31 ms 119376 KB Output is correct
7 Correct 35 ms 119376 KB Output is correct
8 Correct 30 ms 119376 KB Output is correct
9 Correct 34 ms 119624 KB Output is correct
10 Correct 34 ms 119376 KB Output is correct
11 Correct 36 ms 119368 KB Output is correct
12 Correct 32 ms 119376 KB Output is correct
13 Correct 29 ms 119572 KB Output is correct
14 Correct 30 ms 119336 KB Output is correct
15 Correct 37 ms 119376 KB Output is correct
16 Correct 36 ms 119376 KB Output is correct
17 Correct 51 ms 119520 KB Output is correct
18 Correct 49 ms 119568 KB Output is correct
19 Correct 37 ms 119368 KB Output is correct
20 Correct 41 ms 119368 KB Output is correct
21 Correct 38 ms 119368 KB Output is correct
22 Correct 38 ms 119600 KB Output is correct
23 Correct 40 ms 119420 KB Output is correct
24 Correct 40 ms 119444 KB Output is correct
25 Correct 40 ms 119372 KB Output is correct
26 Correct 43 ms 119368 KB Output is correct
27 Correct 38 ms 119376 KB Output is correct
28 Correct 46 ms 119368 KB Output is correct
29 Correct 42 ms 119368 KB Output is correct
30 Correct 44 ms 119412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 119376 KB Output is correct
2 Correct 25 ms 119384 KB Output is correct
3 Correct 19 ms 119376 KB Output is correct
4 Correct 24 ms 119544 KB Output is correct
5 Correct 31 ms 119376 KB Output is correct
6 Correct 31 ms 119376 KB Output is correct
7 Correct 35 ms 119376 KB Output is correct
8 Correct 30 ms 119376 KB Output is correct
9 Correct 34 ms 119624 KB Output is correct
10 Correct 34 ms 119376 KB Output is correct
11 Correct 36 ms 119368 KB Output is correct
12 Correct 32 ms 119376 KB Output is correct
13 Correct 29 ms 119572 KB Output is correct
14 Correct 30 ms 119336 KB Output is correct
15 Correct 37 ms 119376 KB Output is correct
16 Correct 36 ms 119376 KB Output is correct
17 Correct 51 ms 119520 KB Output is correct
18 Correct 49 ms 119568 KB Output is correct
19 Correct 37 ms 119368 KB Output is correct
20 Correct 41 ms 119368 KB Output is correct
21 Correct 38 ms 119368 KB Output is correct
22 Correct 38 ms 119600 KB Output is correct
23 Correct 40 ms 119420 KB Output is correct
24 Correct 40 ms 119444 KB Output is correct
25 Correct 40 ms 119372 KB Output is correct
26 Correct 43 ms 119368 KB Output is correct
27 Correct 38 ms 119376 KB Output is correct
28 Correct 46 ms 119368 KB Output is correct
29 Correct 42 ms 119368 KB Output is correct
30 Correct 44 ms 119412 KB Output is correct
31 Correct 452 ms 133564 KB Output is correct
32 Correct 444 ms 123776 KB Output is correct
33 Correct 493 ms 129720 KB Output is correct
34 Correct 414 ms 129976 KB Output is correct
35 Correct 469 ms 133560 KB Output is correct
36 Correct 464 ms 133424 KB Output is correct
37 Correct 381 ms 128120 KB Output is correct
38 Correct 375 ms 128064 KB Output is correct
39 Correct 301 ms 127672 KB Output is correct
40 Correct 343 ms 127680 KB Output is correct
41 Correct 313 ms 128184 KB Output is correct
42 Correct 238 ms 127928 KB Output is correct
43 Correct 133 ms 125880 KB Output is correct
44 Correct 306 ms 127976 KB Output is correct
45 Correct 294 ms 127928 KB Output is correct
46 Correct 291 ms 127884 KB Output is correct
47 Correct 238 ms 127404 KB Output is correct
48 Correct 239 ms 127416 KB Output is correct
49 Correct 269 ms 127668 KB Output is correct
50 Correct 253 ms 127748 KB Output is correct
51 Correct 282 ms 127672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1853 ms 184144 KB Output is correct
2 Correct 2748 ms 174288 KB Output is correct
3 Correct 1650 ms 218696 KB Output is correct
4 Correct 1779 ms 190040 KB Output is correct
5 Correct 2638 ms 173900 KB Output is correct
6 Correct 2717 ms 174176 KB Output is correct
7 Correct 1477 ms 218760 KB Output is correct
8 Correct 1457 ms 190096 KB Output is correct
9 Correct 1473 ms 179860 KB Output is correct
10 Correct 2169 ms 174988 KB Output is correct
11 Correct 1593 ms 173720 KB Output is correct
12 Correct 1596 ms 174736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2482 ms 183404 KB Output is correct
2 Execution timed out 5054 ms 144996 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 119376 KB Output is correct
2 Correct 25 ms 119384 KB Output is correct
3 Correct 19 ms 119376 KB Output is correct
4 Correct 24 ms 119544 KB Output is correct
5 Correct 31 ms 119376 KB Output is correct
6 Correct 31 ms 119376 KB Output is correct
7 Correct 35 ms 119376 KB Output is correct
8 Correct 30 ms 119376 KB Output is correct
9 Correct 34 ms 119624 KB Output is correct
10 Correct 34 ms 119376 KB Output is correct
11 Correct 36 ms 119368 KB Output is correct
12 Correct 32 ms 119376 KB Output is correct
13 Correct 29 ms 119572 KB Output is correct
14 Correct 30 ms 119336 KB Output is correct
15 Correct 37 ms 119376 KB Output is correct
16 Correct 36 ms 119376 KB Output is correct
17 Correct 51 ms 119520 KB Output is correct
18 Correct 49 ms 119568 KB Output is correct
19 Correct 37 ms 119368 KB Output is correct
20 Correct 41 ms 119368 KB Output is correct
21 Correct 38 ms 119368 KB Output is correct
22 Correct 38 ms 119600 KB Output is correct
23 Correct 40 ms 119420 KB Output is correct
24 Correct 40 ms 119444 KB Output is correct
25 Correct 40 ms 119372 KB Output is correct
26 Correct 43 ms 119368 KB Output is correct
27 Correct 38 ms 119376 KB Output is correct
28 Correct 46 ms 119368 KB Output is correct
29 Correct 42 ms 119368 KB Output is correct
30 Correct 44 ms 119412 KB Output is correct
31 Correct 452 ms 133564 KB Output is correct
32 Correct 444 ms 123776 KB Output is correct
33 Correct 493 ms 129720 KB Output is correct
34 Correct 414 ms 129976 KB Output is correct
35 Correct 469 ms 133560 KB Output is correct
36 Correct 464 ms 133424 KB Output is correct
37 Correct 381 ms 128120 KB Output is correct
38 Correct 375 ms 128064 KB Output is correct
39 Correct 301 ms 127672 KB Output is correct
40 Correct 343 ms 127680 KB Output is correct
41 Correct 313 ms 128184 KB Output is correct
42 Correct 238 ms 127928 KB Output is correct
43 Correct 133 ms 125880 KB Output is correct
44 Correct 306 ms 127976 KB Output is correct
45 Correct 294 ms 127928 KB Output is correct
46 Correct 291 ms 127884 KB Output is correct
47 Correct 238 ms 127404 KB Output is correct
48 Correct 239 ms 127416 KB Output is correct
49 Correct 269 ms 127668 KB Output is correct
50 Correct 253 ms 127748 KB Output is correct
51 Correct 282 ms 127672 KB Output is correct
52 Correct 258 ms 141752 KB Output is correct
53 Correct 251 ms 138168 KB Output is correct
54 Correct 266 ms 137592 KB Output is correct
55 Correct 313 ms 134320 KB Output is correct
56 Correct 311 ms 135096 KB Output is correct
57 Correct 281 ms 129472 KB Output is correct
58 Correct 263 ms 132536 KB Output is correct
59 Correct 269 ms 134988 KB Output is correct
60 Correct 264 ms 129212 KB Output is correct
61 Correct 111 ms 137400 KB Output is correct
62 Correct 297 ms 142008 KB Output is correct
63 Correct 281 ms 136776 KB Output is correct
64 Correct 263 ms 134328 KB Output is correct
65 Correct 287 ms 129976 KB Output is correct
66 Correct 289 ms 128124 KB Output is correct
67 Correct 160 ms 125112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 119376 KB Output is correct
2 Correct 25 ms 119384 KB Output is correct
3 Correct 19 ms 119376 KB Output is correct
4 Correct 24 ms 119544 KB Output is correct
5 Correct 31 ms 119376 KB Output is correct
6 Correct 31 ms 119376 KB Output is correct
7 Correct 35 ms 119376 KB Output is correct
8 Correct 30 ms 119376 KB Output is correct
9 Correct 34 ms 119624 KB Output is correct
10 Correct 34 ms 119376 KB Output is correct
11 Correct 36 ms 119368 KB Output is correct
12 Correct 32 ms 119376 KB Output is correct
13 Correct 29 ms 119572 KB Output is correct
14 Correct 30 ms 119336 KB Output is correct
15 Correct 37 ms 119376 KB Output is correct
16 Correct 36 ms 119376 KB Output is correct
17 Correct 51 ms 119520 KB Output is correct
18 Correct 49 ms 119568 KB Output is correct
19 Correct 37 ms 119368 KB Output is correct
20 Correct 41 ms 119368 KB Output is correct
21 Correct 38 ms 119368 KB Output is correct
22 Correct 38 ms 119600 KB Output is correct
23 Correct 40 ms 119420 KB Output is correct
24 Correct 40 ms 119444 KB Output is correct
25 Correct 40 ms 119372 KB Output is correct
26 Correct 43 ms 119368 KB Output is correct
27 Correct 38 ms 119376 KB Output is correct
28 Correct 46 ms 119368 KB Output is correct
29 Correct 42 ms 119368 KB Output is correct
30 Correct 44 ms 119412 KB Output is correct
31 Correct 452 ms 133564 KB Output is correct
32 Correct 444 ms 123776 KB Output is correct
33 Correct 493 ms 129720 KB Output is correct
34 Correct 414 ms 129976 KB Output is correct
35 Correct 469 ms 133560 KB Output is correct
36 Correct 464 ms 133424 KB Output is correct
37 Correct 381 ms 128120 KB Output is correct
38 Correct 375 ms 128064 KB Output is correct
39 Correct 301 ms 127672 KB Output is correct
40 Correct 343 ms 127680 KB Output is correct
41 Correct 313 ms 128184 KB Output is correct
42 Correct 238 ms 127928 KB Output is correct
43 Correct 133 ms 125880 KB Output is correct
44 Correct 306 ms 127976 KB Output is correct
45 Correct 294 ms 127928 KB Output is correct
46 Correct 291 ms 127884 KB Output is correct
47 Correct 238 ms 127404 KB Output is correct
48 Correct 239 ms 127416 KB Output is correct
49 Correct 269 ms 127668 KB Output is correct
50 Correct 253 ms 127748 KB Output is correct
51 Correct 282 ms 127672 KB Output is correct
52 Correct 1853 ms 184144 KB Output is correct
53 Correct 2748 ms 174288 KB Output is correct
54 Correct 1650 ms 218696 KB Output is correct
55 Correct 1779 ms 190040 KB Output is correct
56 Correct 2638 ms 173900 KB Output is correct
57 Correct 2717 ms 174176 KB Output is correct
58 Correct 1477 ms 218760 KB Output is correct
59 Correct 1457 ms 190096 KB Output is correct
60 Correct 1473 ms 179860 KB Output is correct
61 Correct 2169 ms 174988 KB Output is correct
62 Correct 1593 ms 173720 KB Output is correct
63 Correct 1596 ms 174736 KB Output is correct
64 Correct 2482 ms 183404 KB Output is correct
65 Execution timed out 5054 ms 144996 KB Time limit exceeded
66 Halted 0 ms 0 KB -