답안 #553166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553166 2022-04-25T01:33:01 Z zaneyu 새 집 (APIO18_new_home) C++14
100 / 100
1958 ms 129776 KB
/*input
2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;

#define ld long double
#define pii pair<int,int>
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=9e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
int MOD=2;
const int INF=6e8;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?"\n":"");
    return out;
}
int mult(ll a,ll b){
    if(a<0) a+=MOD;
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
pair<pii,pii> arr[maxn];
#define get(x) lower_bound(ALL(ds),x)-ds.begin();
int cnt[maxn];
vector<pair<pii,int>> v[maxn];
int n,k,q;
int seg[4*maxn];
int ans[maxn];
void upd(int idx,int l,int r,int ql,int qr,int x){
    if(r<ql or l>qr) return;
    if(ql<=l and r<=qr){
        MXTO(seg[idx],x);
        return;
    }
    int mid=(l+r)/2;
    upd(idx*2,l,mid,ql,qr,x),upd(idx*2+1,mid+1,r,ql,qr,x);
}
int query(int idx,int l,int r,int p){
    if(r<p or l>p) return -INF;
    if(l==r) return seg[idx];
    int mid=(l+r)/2;
    return max({query(idx*2,l,mid,p),query(idx*2+1,mid+1,r,p),seg[idx]});
}
vector<int> ds;
vector<pair<pii,int>> qq;
void solve(){
    REP(i,n) v[arr[i].f.s].pb({{arr[i].s.f,i},arr[i].f.f}),v[arr[i].f.s].pb({{arr[i].s.s,i},-arr[i].f.f});
    vector<pair<pii,pii>> vv;
    REP1(i,k){
        sort(ALL(v[i]));
        map<pii,int> s;
        s[{-INF,0}]=s[{INF,0}]=0;
        for(auto x:v[i]){
            if(x.s>0){
                auto b=s.lower_bound({x.s,x.f.s});
                auto a=prev(b);
                vv.pb({{((*a).f.f+(*b).f.f)/2,(*b).f.f},{(*b).s,x.f.f}});
                b->s=x.f.f;
                s[{x.s,x.f.s}]=x.f.f;
            }
            else{
                x.s*=-1;
                auto it=s.lower_bound({x.s,x.f.s});
                auto a=prev(it),b=next(it);
                vv.pb({{((*a).f.f+x.s)/2,x.s},{(*it).s,x.f.f}});
                vv.pb({{(x.s+(*b).f.f)/2,(*b).f.f},{(*b).s,x.f.f}});
                b->s=x.f.f;
                s.erase(it);
            }
        }
        vv.pb({{0,INF},{s[{INF,0}],sz(ds)}});
        v[i].clear();
    }
    REP(i,4*maxn) seg[i]=0;
    sort(ALL(vv)),sort(ALL(qq));
    int p=0;
    for(auto x:qq){
        while(p<sz(vv) and vv[p].f.f<=x.f.f){
            if(vv[p].s.f<vv[p].s.s) upd(1,0,sz(ds)-1,vv[p].s.f,vv[p].s.s-1,vv[p].f.s);
            ++p;
        }
        MXTO(ans[x.s],query(1,0,sz(ds)-1,x.f.s)-x.f.f);
    }
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n>>k>>q;
    vector<pii> vv;
    REP(i,n){
        int x,t,a,b;
        cin>>x>>t>>a>>b;
        x*=2;
        arr[i]={{x,t},{a,b}};
        ds.pb(a),ds.pb(b+1);
        vv.pb({a,t}),vv.pb({b+1,-t});
    }
    REP(i,q){
        int p,y;
        cin>>p>>y;
        p*=2;
        qq.pb({{p,y},i});
        vv.pb({y,i+n+k});
    }
    sort(ALL(vv));
    int asd=0;
    for(auto x:vv){
        if(x.s>=n+k){
            if(asd!=k) ans[x.s-n-k]=INT_MAX;
        }
        else{
            if(x.s<0){
                cnt[-x.s]--;
                if(!cnt[-x.s]) --asd;
            }
            else{
                if(!cnt[x.s]) ++asd;
                cnt[x.s]++;
            }
        }
    }
    SORT_UNIQUE(ds);
    REP(i,n){
        arr[i].s.f=get(arr[i].s.f);
        arr[i].s.s=get(arr[i].s.s+1);
    }
    for(auto &x:qq) x.f.s=upper_bound(ALL(ds),x.f.s)-ds.begin()-1;
    solve();
    for(auto &x:qq) x.f.f=2e8+1-x.f.f;
    REP(i,n) arr[i].f.f=2e8+1-arr[i].f.f;
    solve();
    REP(i,q){
        if(ans[i]==INT_MAX) cout<<-1<<'\n';
        else cout<<ans[i]/2<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 35540 KB Output is correct
2 Correct 21 ms 35540 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35576 KB Output is correct
5 Correct 21 ms 35652 KB Output is correct
6 Correct 21 ms 35712 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 21 ms 35668 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 21 ms 35700 KB Output is correct
11 Correct 21 ms 35596 KB Output is correct
12 Correct 20 ms 35636 KB Output is correct
13 Correct 21 ms 35580 KB Output is correct
14 Correct 21 ms 35564 KB Output is correct
15 Correct 21 ms 35588 KB Output is correct
16 Correct 20 ms 35572 KB Output is correct
17 Correct 21 ms 35564 KB Output is correct
18 Correct 21 ms 35660 KB Output is correct
19 Correct 20 ms 35596 KB Output is correct
20 Correct 20 ms 35608 KB Output is correct
21 Correct 20 ms 35792 KB Output is correct
22 Correct 22 ms 35676 KB Output is correct
23 Correct 20 ms 35680 KB Output is correct
24 Correct 20 ms 35668 KB Output is correct
25 Correct 20 ms 35604 KB Output is correct
26 Correct 22 ms 35696 KB Output is correct
27 Correct 21 ms 35556 KB Output is correct
28 Correct 19 ms 35696 KB Output is correct
29 Correct 20 ms 35668 KB Output is correct
30 Correct 20 ms 35628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 35540 KB Output is correct
2 Correct 21 ms 35540 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35576 KB Output is correct
5 Correct 21 ms 35652 KB Output is correct
6 Correct 21 ms 35712 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 21 ms 35668 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 21 ms 35700 KB Output is correct
11 Correct 21 ms 35596 KB Output is correct
12 Correct 20 ms 35636 KB Output is correct
13 Correct 21 ms 35580 KB Output is correct
14 Correct 21 ms 35564 KB Output is correct
15 Correct 21 ms 35588 KB Output is correct
16 Correct 20 ms 35572 KB Output is correct
17 Correct 21 ms 35564 KB Output is correct
18 Correct 21 ms 35660 KB Output is correct
19 Correct 20 ms 35596 KB Output is correct
20 Correct 20 ms 35608 KB Output is correct
21 Correct 20 ms 35792 KB Output is correct
22 Correct 22 ms 35676 KB Output is correct
23 Correct 20 ms 35680 KB Output is correct
24 Correct 20 ms 35668 KB Output is correct
25 Correct 20 ms 35604 KB Output is correct
26 Correct 22 ms 35696 KB Output is correct
27 Correct 21 ms 35556 KB Output is correct
28 Correct 19 ms 35696 KB Output is correct
29 Correct 20 ms 35668 KB Output is correct
30 Correct 20 ms 35628 KB Output is correct
31 Correct 316 ms 52004 KB Output is correct
32 Correct 201 ms 49276 KB Output is correct
33 Correct 319 ms 51432 KB Output is correct
34 Correct 299 ms 51812 KB Output is correct
35 Correct 311 ms 50888 KB Output is correct
36 Correct 328 ms 51660 KB Output is correct
37 Correct 284 ms 51320 KB Output is correct
38 Correct 300 ms 51588 KB Output is correct
39 Correct 249 ms 51400 KB Output is correct
40 Correct 258 ms 51608 KB Output is correct
41 Correct 241 ms 50656 KB Output is correct
42 Correct 243 ms 51272 KB Output is correct
43 Correct 117 ms 51020 KB Output is correct
44 Correct 235 ms 51128 KB Output is correct
45 Correct 241 ms 50924 KB Output is correct
46 Correct 215 ms 51492 KB Output is correct
47 Correct 181 ms 50804 KB Output is correct
48 Correct 173 ms 50960 KB Output is correct
49 Correct 198 ms 50844 KB Output is correct
50 Correct 216 ms 51748 KB Output is correct
51 Correct 192 ms 50940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 727 ms 110888 KB Output is correct
2 Correct 900 ms 107880 KB Output is correct
3 Correct 773 ms 128136 KB Output is correct
4 Correct 726 ms 111080 KB Output is correct
5 Correct 1194 ms 117852 KB Output is correct
6 Correct 929 ms 109100 KB Output is correct
7 Correct 676 ms 128144 KB Output is correct
8 Correct 673 ms 109812 KB Output is correct
9 Correct 659 ms 108844 KB Output is correct
10 Correct 751 ms 107884 KB Output is correct
11 Correct 690 ms 106748 KB Output is correct
12 Correct 721 ms 107024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1242 ms 108296 KB Output is correct
2 Correct 861 ms 98464 KB Output is correct
3 Correct 1436 ms 108136 KB Output is correct
4 Correct 1197 ms 127844 KB Output is correct
5 Correct 1150 ms 110628 KB Output is correct
6 Correct 1205 ms 110768 KB Output is correct
7 Correct 1958 ms 122428 KB Output is correct
8 Correct 1522 ms 109724 KB Output is correct
9 Correct 1056 ms 127680 KB Output is correct
10 Correct 1067 ms 110056 KB Output is correct
11 Correct 1170 ms 107984 KB Output is correct
12 Correct 1276 ms 107120 KB Output is correct
13 Correct 929 ms 106116 KB Output is correct
14 Correct 961 ms 105532 KB Output is correct
15 Correct 1028 ms 106336 KB Output is correct
16 Correct 1058 ms 106420 KB Output is correct
17 Correct 1105 ms 106740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 35540 KB Output is correct
2 Correct 21 ms 35540 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35576 KB Output is correct
5 Correct 21 ms 35652 KB Output is correct
6 Correct 21 ms 35712 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 21 ms 35668 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 21 ms 35700 KB Output is correct
11 Correct 21 ms 35596 KB Output is correct
12 Correct 20 ms 35636 KB Output is correct
13 Correct 21 ms 35580 KB Output is correct
14 Correct 21 ms 35564 KB Output is correct
15 Correct 21 ms 35588 KB Output is correct
16 Correct 20 ms 35572 KB Output is correct
17 Correct 21 ms 35564 KB Output is correct
18 Correct 21 ms 35660 KB Output is correct
19 Correct 20 ms 35596 KB Output is correct
20 Correct 20 ms 35608 KB Output is correct
21 Correct 20 ms 35792 KB Output is correct
22 Correct 22 ms 35676 KB Output is correct
23 Correct 20 ms 35680 KB Output is correct
24 Correct 20 ms 35668 KB Output is correct
25 Correct 20 ms 35604 KB Output is correct
26 Correct 22 ms 35696 KB Output is correct
27 Correct 21 ms 35556 KB Output is correct
28 Correct 19 ms 35696 KB Output is correct
29 Correct 20 ms 35668 KB Output is correct
30 Correct 20 ms 35628 KB Output is correct
31 Correct 316 ms 52004 KB Output is correct
32 Correct 201 ms 49276 KB Output is correct
33 Correct 319 ms 51432 KB Output is correct
34 Correct 299 ms 51812 KB Output is correct
35 Correct 311 ms 50888 KB Output is correct
36 Correct 328 ms 51660 KB Output is correct
37 Correct 284 ms 51320 KB Output is correct
38 Correct 300 ms 51588 KB Output is correct
39 Correct 249 ms 51400 KB Output is correct
40 Correct 258 ms 51608 KB Output is correct
41 Correct 241 ms 50656 KB Output is correct
42 Correct 243 ms 51272 KB Output is correct
43 Correct 117 ms 51020 KB Output is correct
44 Correct 235 ms 51128 KB Output is correct
45 Correct 241 ms 50924 KB Output is correct
46 Correct 215 ms 51492 KB Output is correct
47 Correct 181 ms 50804 KB Output is correct
48 Correct 173 ms 50960 KB Output is correct
49 Correct 198 ms 50844 KB Output is correct
50 Correct 216 ms 51748 KB Output is correct
51 Correct 192 ms 50940 KB Output is correct
52 Correct 280 ms 52304 KB Output is correct
53 Correct 273 ms 52452 KB Output is correct
54 Correct 269 ms 51820 KB Output is correct
55 Correct 242 ms 51528 KB Output is correct
56 Correct 250 ms 51836 KB Output is correct
57 Correct 236 ms 50928 KB Output is correct
58 Correct 252 ms 51824 KB Output is correct
59 Correct 255 ms 51796 KB Output is correct
60 Correct 245 ms 51464 KB Output is correct
61 Correct 134 ms 51820 KB Output is correct
62 Correct 261 ms 52364 KB Output is correct
63 Correct 263 ms 51884 KB Output is correct
64 Correct 263 ms 51672 KB Output is correct
65 Correct 259 ms 51408 KB Output is correct
66 Correct 249 ms 51376 KB Output is correct
67 Correct 173 ms 49564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 35540 KB Output is correct
2 Correct 21 ms 35540 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35576 KB Output is correct
5 Correct 21 ms 35652 KB Output is correct
6 Correct 21 ms 35712 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 21 ms 35668 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 21 ms 35700 KB Output is correct
11 Correct 21 ms 35596 KB Output is correct
12 Correct 20 ms 35636 KB Output is correct
13 Correct 21 ms 35580 KB Output is correct
14 Correct 21 ms 35564 KB Output is correct
15 Correct 21 ms 35588 KB Output is correct
16 Correct 20 ms 35572 KB Output is correct
17 Correct 21 ms 35564 KB Output is correct
18 Correct 21 ms 35660 KB Output is correct
19 Correct 20 ms 35596 KB Output is correct
20 Correct 20 ms 35608 KB Output is correct
21 Correct 20 ms 35792 KB Output is correct
22 Correct 22 ms 35676 KB Output is correct
23 Correct 20 ms 35680 KB Output is correct
24 Correct 20 ms 35668 KB Output is correct
25 Correct 20 ms 35604 KB Output is correct
26 Correct 22 ms 35696 KB Output is correct
27 Correct 21 ms 35556 KB Output is correct
28 Correct 19 ms 35696 KB Output is correct
29 Correct 20 ms 35668 KB Output is correct
30 Correct 20 ms 35628 KB Output is correct
31 Correct 316 ms 52004 KB Output is correct
32 Correct 201 ms 49276 KB Output is correct
33 Correct 319 ms 51432 KB Output is correct
34 Correct 299 ms 51812 KB Output is correct
35 Correct 311 ms 50888 KB Output is correct
36 Correct 328 ms 51660 KB Output is correct
37 Correct 284 ms 51320 KB Output is correct
38 Correct 300 ms 51588 KB Output is correct
39 Correct 249 ms 51400 KB Output is correct
40 Correct 258 ms 51608 KB Output is correct
41 Correct 241 ms 50656 KB Output is correct
42 Correct 243 ms 51272 KB Output is correct
43 Correct 117 ms 51020 KB Output is correct
44 Correct 235 ms 51128 KB Output is correct
45 Correct 241 ms 50924 KB Output is correct
46 Correct 215 ms 51492 KB Output is correct
47 Correct 181 ms 50804 KB Output is correct
48 Correct 173 ms 50960 KB Output is correct
49 Correct 198 ms 50844 KB Output is correct
50 Correct 216 ms 51748 KB Output is correct
51 Correct 192 ms 50940 KB Output is correct
52 Correct 727 ms 110888 KB Output is correct
53 Correct 900 ms 107880 KB Output is correct
54 Correct 773 ms 128136 KB Output is correct
55 Correct 726 ms 111080 KB Output is correct
56 Correct 1194 ms 117852 KB Output is correct
57 Correct 929 ms 109100 KB Output is correct
58 Correct 676 ms 128144 KB Output is correct
59 Correct 673 ms 109812 KB Output is correct
60 Correct 659 ms 108844 KB Output is correct
61 Correct 751 ms 107884 KB Output is correct
62 Correct 690 ms 106748 KB Output is correct
63 Correct 721 ms 107024 KB Output is correct
64 Correct 1242 ms 108296 KB Output is correct
65 Correct 861 ms 98464 KB Output is correct
66 Correct 1436 ms 108136 KB Output is correct
67 Correct 1197 ms 127844 KB Output is correct
68 Correct 1150 ms 110628 KB Output is correct
69 Correct 1205 ms 110768 KB Output is correct
70 Correct 1958 ms 122428 KB Output is correct
71 Correct 1522 ms 109724 KB Output is correct
72 Correct 1056 ms 127680 KB Output is correct
73 Correct 1067 ms 110056 KB Output is correct
74 Correct 1170 ms 107984 KB Output is correct
75 Correct 1276 ms 107120 KB Output is correct
76 Correct 929 ms 106116 KB Output is correct
77 Correct 961 ms 105532 KB Output is correct
78 Correct 1028 ms 106336 KB Output is correct
79 Correct 1058 ms 106420 KB Output is correct
80 Correct 1105 ms 106740 KB Output is correct
81 Correct 280 ms 52304 KB Output is correct
82 Correct 273 ms 52452 KB Output is correct
83 Correct 269 ms 51820 KB Output is correct
84 Correct 242 ms 51528 KB Output is correct
85 Correct 250 ms 51836 KB Output is correct
86 Correct 236 ms 50928 KB Output is correct
87 Correct 252 ms 51824 KB Output is correct
88 Correct 255 ms 51796 KB Output is correct
89 Correct 245 ms 51464 KB Output is correct
90 Correct 134 ms 51820 KB Output is correct
91 Correct 261 ms 52364 KB Output is correct
92 Correct 263 ms 51884 KB Output is correct
93 Correct 263 ms 51672 KB Output is correct
94 Correct 259 ms 51408 KB Output is correct
95 Correct 249 ms 51376 KB Output is correct
96 Correct 173 ms 49564 KB Output is correct
97 Correct 1552 ms 129628 KB Output is correct
98 Correct 950 ms 99560 KB Output is correct
99 Correct 1864 ms 109168 KB Output is correct
100 Correct 1536 ms 129752 KB Output is correct
101 Correct 1520 ms 112920 KB Output is correct
102 Correct 1904 ms 110372 KB Output is correct
103 Correct 1544 ms 109268 KB Output is correct
104 Correct 1656 ms 109372 KB Output is correct
105 Correct 1347 ms 108844 KB Output is correct
106 Correct 1419 ms 109400 KB Output is correct
107 Correct 1283 ms 110608 KB Output is correct
108 Correct 1299 ms 128780 KB Output is correct
109 Correct 1282 ms 111888 KB Output is correct
110 Correct 1346 ms 111688 KB Output is correct
111 Correct 1358 ms 129204 KB Output is correct
112 Correct 1304 ms 110392 KB Output is correct
113 Correct 579 ms 126684 KB Output is correct
114 Correct 1423 ms 129776 KB Output is correct
115 Correct 1441 ms 129772 KB Output is correct
116 Correct 1402 ms 111772 KB Output is correct
117 Correct 1475 ms 111180 KB Output is correct
118 Correct 1317 ms 110356 KB Output is correct
119 Correct 805 ms 101436 KB Output is correct
120 Correct 810 ms 106588 KB Output is correct
121 Correct 889 ms 107196 KB Output is correct
122 Correct 873 ms 106640 KB Output is correct
123 Correct 965 ms 108200 KB Output is correct
124 Correct 1088 ms 108968 KB Output is correct
125 Correct 992 ms 108756 KB Output is correct
126 Correct 1132 ms 111984 KB Output is correct