답안 #924632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924632 2024-02-09T10:32:53 Z winter0101 새 집 (APIO18_new_home) C++17
80 / 100
5000 ms 405724 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=3e5+9;
const int mx=2e8;
const int mn=-1e8;
set<int>cord[maxn];
multiset<int>dubi[maxn];
int n,k,q,line;
int now=0;
struct lne{
int l,r,tim;
bool operator < (const lne &p)const {
if (l==p.l&&r==p.r)return tim<p.tim;
if (l==p.l)return r<p.r;
return l<p.l;
}
};
multiset<lne>temp[maxn];
vector<pii>st[maxn*3*4];
void update(int id,int l,int r,int u,int v,const pii &x){
if (l>v||r<u||u>v)return;
if (u<=l&&r<=v){
st[id].pb(x);
return;
}
int mid=(l+r)>>1;
update(id<<1,l,mid,u,v,x);
update(id<<1|1,mid+1,r,u,v,x);
}
void add_line(int l,int r,int type,int tme){
temp[type].insert({l,r,tme});
}
void del_line(int l,int r,int type,int del){
auto it=temp[type].lower_bound({l,r,0});
auto tmp=(*it);
update(1,1,line,tmp.tim,del-1,{tmp.l,tmp.r});
temp[type].erase(it);
}
void add_point(int x,int type,int tme){
if (cord[type].empty())now++;
if (cord[type].find(x)!=cord[type].end()){
dubi[type].insert(x);
return;
}
if (cord[type].empty()){
cord[type].insert(x);
add_line(mn,x,type,tme);
add_line(x,mx,type,tme);
return;
}
auto it=cord[type].upper_bound(x);
if (it==cord[type].end()){
it--;
del_line((*it),mx,type,tme);
add_line(x,mx,type,tme);
add_line((*it),x,type,tme);
cord[type].insert(x);
return;
}
if (it==cord[type].begin()){
del_line(mn,(*it),type,tme);
add_line(x,(*it),type,tme);
add_line(mn,x,type,tme);
cord[type].insert(x);
return;
}
int l1,r1=(*it);
it--;
l1=(*it);
del_line(l1,r1,type,tme);
add_line(x,r1,type,tme);
add_line(l1,x,type,tme);
cord[type].insert(x);
return;
}
void del_point(int x,int type,int tme){
if (dubi[type].find(x)!=dubi[type].end()){
dubi[type].erase(dubi[type].find(x));
return;
}
if (sz(cord[type])==1)now--;
cord[type].erase(x);
if (cord[type].empty()){
del_line(mn,x,type,tme);
del_line(x,mx,type,tme);
return;
}
auto it=cord[type].upper_bound(x);
if (it==cord[type].end()){
it--;
del_line((*it),x,type,tme);
del_line(x,mx,type,tme);
add_line((*it),mx,type,tme);
return;
}
if (it==cord[type].begin()){
del_line(mn,x,type,tme);
del_line(x,(*it),type,tme);
add_line(mn,(*it),type,tme);
return;
}
int l1,r1=(*it);
it--;
l1=(*it);
del_line(l1,x,type,tme);
del_line(x,r1,type,tme);
add_line(l1,r1,type,tme);
return;
}
struct store{
int x,t,a,b;
}a[maxn];
pii b[maxn];
vector<int>add[maxn*3],del[maxn*3];
vector<int>answer[maxn*3];
int st1[maxn*4],st2[maxn*4],c[maxn];
/*
1 for a-x
2 for x-a
*/
void build(int id,int l,int r){
st1[id]=mx,st2[id]=mn;
if (l==r)return;
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
}
void upd1(int id,int l,int r,int u,int v,int val){
if (l>v||r<u||u>v)return;
if (u<=l&&r<=v){
st1[id]=min(st1[id],val);
return;
}
int mid=(l+r)>>1;
upd1(id<<1,l,mid,u,v,val);
upd1(id<<1|1,mid+1,r,u,v,val);
}
void upd2(int id,int l,int r,int u,int v,int val){
if (l>v||r<u||u>v)return;
if (u<=l&&r<=v){
st2[id]=max(st2[id],val);
return;
}
int mid=(l+r)>>1;
upd2(id<<1,l,mid,u,v,val);
upd2(id<<1|1,mid+1,r,u,v,val);
}
pii get(int id,int l,int r,int u){
pii xxx={mx,mn};
while (true){
xxx.fi=min(xxx.fi,st1[id]);
xxx.se=max(xxx.se,st2[id]);
if (l==r)break;
int mid=(l+r)>>1;
if (mid>=u){
id=(id<<1);
r=mid;
}
else {
id=(id<<1|1);
l=mid+1;
}
}
return xxx;
}
void new_home(int id,int l,int r){
if (!st[id].empty()){
vector<int>cc;
for1(i,l,r){
for (auto v:answer[i]){
if (c[v]==-1)continue;
cc.pb(b[v].fi);
}
}
sort(all(cc));
cc.resize(distance(cc.begin(),unique(all(cc))));
if (!cc.empty()){
int m=sz(cc);
build(1,1,m);
for(auto v:st[id]){
int l1=v.fi,r1=v.se,mid=(l1+r1)/2;
l1=lower_bound(all(cc),l1)-cc.begin()+1;
r1=upper_bound(all(cc),r1)-cc.begin();
mid=upper_bound(all(cc),mid)-cc.begin();
upd1(1,1,m,l1,mid,v.fi);
upd2(1,1,m,mid+1,r1,v.se);
}
for1(i,l,r){
for (auto v:answer[i]){
if (c[v]==-1)continue;
int pos=lower_bound(all(cc),b[v].fi)-cc.begin()+1;
pii xxx=get(1,1,m,pos);
c[v]=max({c[v],b[v].fi-xxx.fi,xxx.se-b[v].fi});
}
}
}
}
if (l==r)return;
int mid=(l+r)>>1;
new_home(id<<1,l,mid);
new_home(id<<1|1,mid+1,r);
}
void init(){
    cin>>n>>k>>q;
    for1(i,1,n)cin>>a[i].x>>a[i].t>>a[i].a>>a[i].b;
    for1(i,1,q)cin>>b[i].fi>>b[i].se;
}
void nentime(){
    vector<int>tme;
    for1(i,1,n){
    tme.pb(a[i].a),tme.pb(a[i].b);
    }
    for1(i,1,q){
    tme.pb(b[i].se);
    }
    sort(all(tme));
    tme.resize(distance(tme.begin(),unique(all(tme))));
    map<int,int>nn;
    for1(i,0,sz(tme)-1)nn[tme[i]]=i+1;
    for1(i,1,n){
    a[i].a=nn[a[i].a],a[i].b=nn[a[i].b];
    add[a[i].a].pb(i);
    del[a[i].b].pb(i);
    }
    for1(i,1,q){
    b[i].se=nn[b[i].se];
    answer[b[i].se].pb(i);
    }
    line=sz(tme);
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    init();
    nentime();
    for1(i,1,line){
    for (auto v:add[i]){
    add_point(a[v].x,a[v].t,i);
    }
    for (auto v:answer[i]){
    if (now<k){
    c[v]=-1;
    continue;
    }
    }
    for (auto v:del[i]){
    del_point(a[v].x,a[v].t,i+1);
    }
    }
    for1(i,1,k){
    for (auto u:temp[i]){
    update(1,1,line,u.tim,line,{u.l,u.r});
    }
    }
    new_home(1,1,line);
    for1(i,1,q)cout<<c[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 197716 KB Output is correct
2 Correct 42 ms 193616 KB Output is correct
3 Correct 41 ms 193740 KB Output is correct
4 Correct 42 ms 197720 KB Output is correct
5 Correct 43 ms 197724 KB Output is correct
6 Correct 44 ms 197972 KB Output is correct
7 Correct 42 ms 193868 KB Output is correct
8 Correct 43 ms 198048 KB Output is correct
9 Correct 43 ms 197976 KB Output is correct
10 Correct 44 ms 197980 KB Output is correct
11 Correct 43 ms 193884 KB Output is correct
12 Correct 44 ms 197956 KB Output is correct
13 Correct 43 ms 197988 KB Output is correct
14 Correct 42 ms 198224 KB Output is correct
15 Correct 44 ms 198036 KB Output is correct
16 Correct 44 ms 197980 KB Output is correct
17 Correct 43 ms 197988 KB Output is correct
18 Correct 45 ms 197968 KB Output is correct
19 Correct 44 ms 198228 KB Output is correct
20 Correct 44 ms 197968 KB Output is correct
21 Correct 43 ms 197712 KB Output is correct
22 Correct 46 ms 198224 KB Output is correct
23 Correct 44 ms 197968 KB Output is correct
24 Correct 43 ms 197968 KB Output is correct
25 Correct 44 ms 197968 KB Output is correct
26 Correct 44 ms 197980 KB Output is correct
27 Correct 44 ms 197904 KB Output is correct
28 Correct 44 ms 198020 KB Output is correct
29 Correct 44 ms 197968 KB Output is correct
30 Correct 44 ms 197864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 197716 KB Output is correct
2 Correct 42 ms 193616 KB Output is correct
3 Correct 41 ms 193740 KB Output is correct
4 Correct 42 ms 197720 KB Output is correct
5 Correct 43 ms 197724 KB Output is correct
6 Correct 44 ms 197972 KB Output is correct
7 Correct 42 ms 193868 KB Output is correct
8 Correct 43 ms 198048 KB Output is correct
9 Correct 43 ms 197976 KB Output is correct
10 Correct 44 ms 197980 KB Output is correct
11 Correct 43 ms 193884 KB Output is correct
12 Correct 44 ms 197956 KB Output is correct
13 Correct 43 ms 197988 KB Output is correct
14 Correct 42 ms 198224 KB Output is correct
15 Correct 44 ms 198036 KB Output is correct
16 Correct 44 ms 197980 KB Output is correct
17 Correct 43 ms 197988 KB Output is correct
18 Correct 45 ms 197968 KB Output is correct
19 Correct 44 ms 198228 KB Output is correct
20 Correct 44 ms 197968 KB Output is correct
21 Correct 43 ms 197712 KB Output is correct
22 Correct 46 ms 198224 KB Output is correct
23 Correct 44 ms 197968 KB Output is correct
24 Correct 43 ms 197968 KB Output is correct
25 Correct 44 ms 197968 KB Output is correct
26 Correct 44 ms 197980 KB Output is correct
27 Correct 44 ms 197904 KB Output is correct
28 Correct 44 ms 198020 KB Output is correct
29 Correct 44 ms 197968 KB Output is correct
30 Correct 44 ms 197864 KB Output is correct
31 Correct 943 ms 239616 KB Output is correct
32 Correct 91 ms 200972 KB Output is correct
33 Correct 769 ms 238132 KB Output is correct
34 Correct 860 ms 237948 KB Output is correct
35 Correct 927 ms 239420 KB Output is correct
36 Correct 853 ms 239144 KB Output is correct
37 Correct 617 ms 233652 KB Output is correct
38 Correct 586 ms 233648 KB Output is correct
39 Correct 401 ms 226808 KB Output is correct
40 Correct 435 ms 228588 KB Output is correct
41 Correct 515 ms 231412 KB Output is correct
42 Correct 468 ms 231444 KB Output is correct
43 Correct 88 ms 202164 KB Output is correct
44 Correct 490 ms 230392 KB Output is correct
45 Correct 402 ms 226748 KB Output is correct
46 Correct 280 ms 220308 KB Output is correct
47 Correct 247 ms 219440 KB Output is correct
48 Correct 246 ms 218040 KB Output is correct
49 Correct 308 ms 222456 KB Output is correct
50 Correct 368 ms 229168 KB Output is correct
51 Correct 266 ms 220684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1302 ms 281824 KB Output is correct
2 Correct 1716 ms 275148 KB Output is correct
3 Correct 1020 ms 289048 KB Output is correct
4 Correct 1256 ms 283808 KB Output is correct
5 Correct 1677 ms 273692 KB Output is correct
6 Correct 1711 ms 274160 KB Output is correct
7 Correct 893 ms 288932 KB Output is correct
8 Correct 1002 ms 277216 KB Output is correct
9 Correct 994 ms 271836 KB Output is correct
10 Correct 1078 ms 268868 KB Output is correct
11 Correct 853 ms 267300 KB Output is correct
12 Correct 871 ms 268728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4643 ms 341972 KB Output is correct
2 Correct 326 ms 223500 KB Output is correct
3 Correct 4462 ms 339828 KB Output is correct
4 Correct 1459 ms 330668 KB Output is correct
5 Correct 1954 ms 335584 KB Output is correct
6 Correct 1880 ms 334544 KB Output is correct
7 Correct 4317 ms 339824 KB Output is correct
8 Correct 4458 ms 339932 KB Output is correct
9 Correct 1643 ms 330492 KB Output is correct
10 Correct 3592 ms 341820 KB Output is correct
11 Correct 4609 ms 342704 KB Output is correct
12 Correct 4209 ms 341232 KB Output is correct
13 Correct 1853 ms 301776 KB Output is correct
14 Correct 1778 ms 300296 KB Output is correct
15 Correct 2311 ms 311396 KB Output is correct
16 Correct 2710 ms 322048 KB Output is correct
17 Correct 2460 ms 317288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 197716 KB Output is correct
2 Correct 42 ms 193616 KB Output is correct
3 Correct 41 ms 193740 KB Output is correct
4 Correct 42 ms 197720 KB Output is correct
5 Correct 43 ms 197724 KB Output is correct
6 Correct 44 ms 197972 KB Output is correct
7 Correct 42 ms 193868 KB Output is correct
8 Correct 43 ms 198048 KB Output is correct
9 Correct 43 ms 197976 KB Output is correct
10 Correct 44 ms 197980 KB Output is correct
11 Correct 43 ms 193884 KB Output is correct
12 Correct 44 ms 197956 KB Output is correct
13 Correct 43 ms 197988 KB Output is correct
14 Correct 42 ms 198224 KB Output is correct
15 Correct 44 ms 198036 KB Output is correct
16 Correct 44 ms 197980 KB Output is correct
17 Correct 43 ms 197988 KB Output is correct
18 Correct 45 ms 197968 KB Output is correct
19 Correct 44 ms 198228 KB Output is correct
20 Correct 44 ms 197968 KB Output is correct
21 Correct 43 ms 197712 KB Output is correct
22 Correct 46 ms 198224 KB Output is correct
23 Correct 44 ms 197968 KB Output is correct
24 Correct 43 ms 197968 KB Output is correct
25 Correct 44 ms 197968 KB Output is correct
26 Correct 44 ms 197980 KB Output is correct
27 Correct 44 ms 197904 KB Output is correct
28 Correct 44 ms 198020 KB Output is correct
29 Correct 44 ms 197968 KB Output is correct
30 Correct 44 ms 197864 KB Output is correct
31 Correct 943 ms 239616 KB Output is correct
32 Correct 91 ms 200972 KB Output is correct
33 Correct 769 ms 238132 KB Output is correct
34 Correct 860 ms 237948 KB Output is correct
35 Correct 927 ms 239420 KB Output is correct
36 Correct 853 ms 239144 KB Output is correct
37 Correct 617 ms 233652 KB Output is correct
38 Correct 586 ms 233648 KB Output is correct
39 Correct 401 ms 226808 KB Output is correct
40 Correct 435 ms 228588 KB Output is correct
41 Correct 515 ms 231412 KB Output is correct
42 Correct 468 ms 231444 KB Output is correct
43 Correct 88 ms 202164 KB Output is correct
44 Correct 490 ms 230392 KB Output is correct
45 Correct 402 ms 226748 KB Output is correct
46 Correct 280 ms 220308 KB Output is correct
47 Correct 247 ms 219440 KB Output is correct
48 Correct 246 ms 218040 KB Output is correct
49 Correct 308 ms 222456 KB Output is correct
50 Correct 368 ms 229168 KB Output is correct
51 Correct 266 ms 220684 KB Output is correct
52 Correct 360 ms 229448 KB Output is correct
53 Correct 320 ms 227928 KB Output is correct
54 Correct 443 ms 238496 KB Output is correct
55 Correct 529 ms 233680 KB Output is correct
56 Correct 523 ms 233728 KB Output is correct
57 Correct 570 ms 232564 KB Output is correct
58 Correct 488 ms 232964 KB Output is correct
59 Correct 486 ms 233308 KB Output is correct
60 Correct 492 ms 231876 KB Output is correct
61 Correct 85 ms 209160 KB Output is correct
62 Correct 391 ms 236408 KB Output is correct
63 Correct 625 ms 237868 KB Output is correct
64 Correct 750 ms 239176 KB Output is correct
65 Correct 744 ms 238632 KB Output is correct
66 Correct 589 ms 233724 KB Output is correct
67 Correct 158 ms 207576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 197716 KB Output is correct
2 Correct 42 ms 193616 KB Output is correct
3 Correct 41 ms 193740 KB Output is correct
4 Correct 42 ms 197720 KB Output is correct
5 Correct 43 ms 197724 KB Output is correct
6 Correct 44 ms 197972 KB Output is correct
7 Correct 42 ms 193868 KB Output is correct
8 Correct 43 ms 198048 KB Output is correct
9 Correct 43 ms 197976 KB Output is correct
10 Correct 44 ms 197980 KB Output is correct
11 Correct 43 ms 193884 KB Output is correct
12 Correct 44 ms 197956 KB Output is correct
13 Correct 43 ms 197988 KB Output is correct
14 Correct 42 ms 198224 KB Output is correct
15 Correct 44 ms 198036 KB Output is correct
16 Correct 44 ms 197980 KB Output is correct
17 Correct 43 ms 197988 KB Output is correct
18 Correct 45 ms 197968 KB Output is correct
19 Correct 44 ms 198228 KB Output is correct
20 Correct 44 ms 197968 KB Output is correct
21 Correct 43 ms 197712 KB Output is correct
22 Correct 46 ms 198224 KB Output is correct
23 Correct 44 ms 197968 KB Output is correct
24 Correct 43 ms 197968 KB Output is correct
25 Correct 44 ms 197968 KB Output is correct
26 Correct 44 ms 197980 KB Output is correct
27 Correct 44 ms 197904 KB Output is correct
28 Correct 44 ms 198020 KB Output is correct
29 Correct 44 ms 197968 KB Output is correct
30 Correct 44 ms 197864 KB Output is correct
31 Correct 943 ms 239616 KB Output is correct
32 Correct 91 ms 200972 KB Output is correct
33 Correct 769 ms 238132 KB Output is correct
34 Correct 860 ms 237948 KB Output is correct
35 Correct 927 ms 239420 KB Output is correct
36 Correct 853 ms 239144 KB Output is correct
37 Correct 617 ms 233652 KB Output is correct
38 Correct 586 ms 233648 KB Output is correct
39 Correct 401 ms 226808 KB Output is correct
40 Correct 435 ms 228588 KB Output is correct
41 Correct 515 ms 231412 KB Output is correct
42 Correct 468 ms 231444 KB Output is correct
43 Correct 88 ms 202164 KB Output is correct
44 Correct 490 ms 230392 KB Output is correct
45 Correct 402 ms 226748 KB Output is correct
46 Correct 280 ms 220308 KB Output is correct
47 Correct 247 ms 219440 KB Output is correct
48 Correct 246 ms 218040 KB Output is correct
49 Correct 308 ms 222456 KB Output is correct
50 Correct 368 ms 229168 KB Output is correct
51 Correct 266 ms 220684 KB Output is correct
52 Correct 1302 ms 281824 KB Output is correct
53 Correct 1716 ms 275148 KB Output is correct
54 Correct 1020 ms 289048 KB Output is correct
55 Correct 1256 ms 283808 KB Output is correct
56 Correct 1677 ms 273692 KB Output is correct
57 Correct 1711 ms 274160 KB Output is correct
58 Correct 893 ms 288932 KB Output is correct
59 Correct 1002 ms 277216 KB Output is correct
60 Correct 994 ms 271836 KB Output is correct
61 Correct 1078 ms 268868 KB Output is correct
62 Correct 853 ms 267300 KB Output is correct
63 Correct 871 ms 268728 KB Output is correct
64 Correct 4643 ms 341972 KB Output is correct
65 Correct 326 ms 223500 KB Output is correct
66 Correct 4462 ms 339828 KB Output is correct
67 Correct 1459 ms 330668 KB Output is correct
68 Correct 1954 ms 335584 KB Output is correct
69 Correct 1880 ms 334544 KB Output is correct
70 Correct 4317 ms 339824 KB Output is correct
71 Correct 4458 ms 339932 KB Output is correct
72 Correct 1643 ms 330492 KB Output is correct
73 Correct 3592 ms 341820 KB Output is correct
74 Correct 4609 ms 342704 KB Output is correct
75 Correct 4209 ms 341232 KB Output is correct
76 Correct 1853 ms 301776 KB Output is correct
77 Correct 1778 ms 300296 KB Output is correct
78 Correct 2311 ms 311396 KB Output is correct
79 Correct 2710 ms 322048 KB Output is correct
80 Correct 2460 ms 317288 KB Output is correct
81 Correct 360 ms 229448 KB Output is correct
82 Correct 320 ms 227928 KB Output is correct
83 Correct 443 ms 238496 KB Output is correct
84 Correct 529 ms 233680 KB Output is correct
85 Correct 523 ms 233728 KB Output is correct
86 Correct 570 ms 232564 KB Output is correct
87 Correct 488 ms 232964 KB Output is correct
88 Correct 486 ms 233308 KB Output is correct
89 Correct 492 ms 231876 KB Output is correct
90 Correct 85 ms 209160 KB Output is correct
91 Correct 391 ms 236408 KB Output is correct
92 Correct 625 ms 237868 KB Output is correct
93 Correct 750 ms 239176 KB Output is correct
94 Correct 744 ms 238632 KB Output is correct
95 Correct 589 ms 233724 KB Output is correct
96 Correct 158 ms 207576 KB Output is correct
97 Correct 2363 ms 390220 KB Output is correct
98 Correct 354 ms 216468 KB Output is correct
99 Execution timed out 5020 ms 405724 KB Time limit exceeded
100 Halted 0 ms 0 KB -