Submission #924637

# Submission time Handle Problem Language Result Execution time Memory
924637 2024-02-09T10:44:30 Z winter0101 New Home (APIO18_new_home) C++17
100 / 100
4895 ms 338176 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*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,q){
    tme.pb(b[i].se);
    }
    sort(all(tme));
    tme.resize(distance(tme.begin(),unique(all(tme))));
    for1(i,1,n){
    a[i].a=lower_bound(all(tme),a[i].a)-tme.begin()+1,a[i].b=upper_bound(all(tme),a[i].b)-tme.begin();
    if (a[i].a>a[i].b)continue;
    add[a[i].a].pb(i);
    del[a[i].b].pb(i);
    }
    for1(i,1,q){
    b[i].se=lower_bound(all(tme),b[i].se)-tme.begin()+1;
    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';
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 141404 KB Output is correct
2 Correct 29 ms 137296 KB Output is correct
3 Correct 30 ms 137536 KB Output is correct
4 Correct 30 ms 141396 KB Output is correct
5 Correct 31 ms 141400 KB Output is correct
6 Correct 35 ms 141392 KB Output is correct
7 Correct 35 ms 137300 KB Output is correct
8 Correct 31 ms 141396 KB Output is correct
9 Correct 31 ms 141404 KB Output is correct
10 Correct 31 ms 141492 KB Output is correct
11 Correct 30 ms 137300 KB Output is correct
12 Correct 31 ms 141392 KB Output is correct
13 Correct 31 ms 141404 KB Output is correct
14 Correct 31 ms 141396 KB Output is correct
15 Correct 31 ms 141408 KB Output is correct
16 Correct 35 ms 141392 KB Output is correct
17 Correct 31 ms 141484 KB Output is correct
18 Correct 32 ms 141628 KB Output is correct
19 Correct 32 ms 141392 KB Output is correct
20 Correct 33 ms 141392 KB Output is correct
21 Correct 30 ms 141396 KB Output is correct
22 Correct 31 ms 141660 KB Output is correct
23 Correct 31 ms 141660 KB Output is correct
24 Correct 32 ms 141400 KB Output is correct
25 Correct 36 ms 141396 KB Output is correct
26 Correct 31 ms 141396 KB Output is correct
27 Correct 30 ms 141396 KB Output is correct
28 Correct 32 ms 141400 KB Output is correct
29 Correct 31 ms 141396 KB Output is correct
30 Correct 30 ms 141404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 141404 KB Output is correct
2 Correct 29 ms 137296 KB Output is correct
3 Correct 30 ms 137536 KB Output is correct
4 Correct 30 ms 141396 KB Output is correct
5 Correct 31 ms 141400 KB Output is correct
6 Correct 35 ms 141392 KB Output is correct
7 Correct 35 ms 137300 KB Output is correct
8 Correct 31 ms 141396 KB Output is correct
9 Correct 31 ms 141404 KB Output is correct
10 Correct 31 ms 141492 KB Output is correct
11 Correct 30 ms 137300 KB Output is correct
12 Correct 31 ms 141392 KB Output is correct
13 Correct 31 ms 141404 KB Output is correct
14 Correct 31 ms 141396 KB Output is correct
15 Correct 31 ms 141408 KB Output is correct
16 Correct 35 ms 141392 KB Output is correct
17 Correct 31 ms 141484 KB Output is correct
18 Correct 32 ms 141628 KB Output is correct
19 Correct 32 ms 141392 KB Output is correct
20 Correct 33 ms 141392 KB Output is correct
21 Correct 30 ms 141396 KB Output is correct
22 Correct 31 ms 141660 KB Output is correct
23 Correct 31 ms 141660 KB Output is correct
24 Correct 32 ms 141400 KB Output is correct
25 Correct 36 ms 141396 KB Output is correct
26 Correct 31 ms 141396 KB Output is correct
27 Correct 30 ms 141396 KB Output is correct
28 Correct 32 ms 141400 KB Output is correct
29 Correct 31 ms 141396 KB Output is correct
30 Correct 30 ms 141404 KB Output is correct
31 Correct 825 ms 176732 KB Output is correct
32 Correct 81 ms 144364 KB Output is correct
33 Correct 611 ms 173776 KB Output is correct
34 Correct 695 ms 173984 KB Output is correct
35 Correct 781 ms 176424 KB Output is correct
36 Correct 672 ms 176436 KB Output is correct
37 Correct 458 ms 168620 KB Output is correct
38 Correct 439 ms 168420 KB Output is correct
39 Correct 279 ms 161752 KB Output is correct
40 Correct 318 ms 163228 KB Output is correct
41 Correct 392 ms 165932 KB Output is correct
42 Correct 297 ms 166188 KB Output is correct
43 Correct 65 ms 144976 KB Output is correct
44 Correct 360 ms 165404 KB Output is correct
45 Correct 313 ms 161828 KB Output is correct
46 Correct 170 ms 156040 KB Output is correct
47 Correct 150 ms 155432 KB Output is correct
48 Correct 141 ms 154212 KB Output is correct
49 Correct 225 ms 157936 KB Output is correct
50 Correct 248 ms 164164 KB Output is correct
51 Correct 173 ms 156536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1052 ms 214872 KB Output is correct
2 Correct 1503 ms 209276 KB Output is correct
3 Correct 885 ms 226028 KB Output is correct
4 Correct 1002 ms 217068 KB Output is correct
5 Correct 1386 ms 208256 KB Output is correct
6 Correct 1482 ms 207780 KB Output is correct
7 Correct 707 ms 226068 KB Output is correct
8 Correct 808 ms 213404 KB Output is correct
9 Correct 855 ms 208760 KB Output is correct
10 Correct 941 ms 206144 KB Output is correct
11 Correct 713 ms 204912 KB Output is correct
12 Correct 745 ms 206284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4073 ms 266912 KB Output is correct
2 Correct 311 ms 165248 KB Output is correct
3 Correct 3680 ms 265364 KB Output is correct
4 Correct 827 ms 261168 KB Output is correct
5 Correct 1297 ms 261932 KB Output is correct
6 Correct 1206 ms 261360 KB Output is correct
7 Correct 3573 ms 264668 KB Output is correct
8 Correct 3541 ms 265532 KB Output is correct
9 Correct 1152 ms 267316 KB Output is correct
10 Correct 2891 ms 268144 KB Output is correct
11 Correct 3914 ms 266656 KB Output is correct
12 Correct 3641 ms 265128 KB Output is correct
13 Correct 1409 ms 227760 KB Output is correct
14 Correct 1393 ms 227632 KB Output is correct
15 Correct 1829 ms 240084 KB Output is correct
16 Correct 2309 ms 248672 KB Output is correct
17 Correct 2009 ms 245168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 141404 KB Output is correct
2 Correct 29 ms 137296 KB Output is correct
3 Correct 30 ms 137536 KB Output is correct
4 Correct 30 ms 141396 KB Output is correct
5 Correct 31 ms 141400 KB Output is correct
6 Correct 35 ms 141392 KB Output is correct
7 Correct 35 ms 137300 KB Output is correct
8 Correct 31 ms 141396 KB Output is correct
9 Correct 31 ms 141404 KB Output is correct
10 Correct 31 ms 141492 KB Output is correct
11 Correct 30 ms 137300 KB Output is correct
12 Correct 31 ms 141392 KB Output is correct
13 Correct 31 ms 141404 KB Output is correct
14 Correct 31 ms 141396 KB Output is correct
15 Correct 31 ms 141408 KB Output is correct
16 Correct 35 ms 141392 KB Output is correct
17 Correct 31 ms 141484 KB Output is correct
18 Correct 32 ms 141628 KB Output is correct
19 Correct 32 ms 141392 KB Output is correct
20 Correct 33 ms 141392 KB Output is correct
21 Correct 30 ms 141396 KB Output is correct
22 Correct 31 ms 141660 KB Output is correct
23 Correct 31 ms 141660 KB Output is correct
24 Correct 32 ms 141400 KB Output is correct
25 Correct 36 ms 141396 KB Output is correct
26 Correct 31 ms 141396 KB Output is correct
27 Correct 30 ms 141396 KB Output is correct
28 Correct 32 ms 141400 KB Output is correct
29 Correct 31 ms 141396 KB Output is correct
30 Correct 30 ms 141404 KB Output is correct
31 Correct 825 ms 176732 KB Output is correct
32 Correct 81 ms 144364 KB Output is correct
33 Correct 611 ms 173776 KB Output is correct
34 Correct 695 ms 173984 KB Output is correct
35 Correct 781 ms 176424 KB Output is correct
36 Correct 672 ms 176436 KB Output is correct
37 Correct 458 ms 168620 KB Output is correct
38 Correct 439 ms 168420 KB Output is correct
39 Correct 279 ms 161752 KB Output is correct
40 Correct 318 ms 163228 KB Output is correct
41 Correct 392 ms 165932 KB Output is correct
42 Correct 297 ms 166188 KB Output is correct
43 Correct 65 ms 144976 KB Output is correct
44 Correct 360 ms 165404 KB Output is correct
45 Correct 313 ms 161828 KB Output is correct
46 Correct 170 ms 156040 KB Output is correct
47 Correct 150 ms 155432 KB Output is correct
48 Correct 141 ms 154212 KB Output is correct
49 Correct 225 ms 157936 KB Output is correct
50 Correct 248 ms 164164 KB Output is correct
51 Correct 173 ms 156536 KB Output is correct
52 Correct 193 ms 169600 KB Output is correct
53 Correct 202 ms 165928 KB Output is correct
54 Correct 278 ms 176324 KB Output is correct
55 Correct 435 ms 173632 KB Output is correct
56 Correct 444 ms 175840 KB Output is correct
57 Correct 402 ms 168160 KB Output is correct
58 Correct 354 ms 170012 KB Output is correct
59 Correct 325 ms 171744 KB Output is correct
60 Correct 336 ms 167520 KB Output is correct
61 Correct 74 ms 151912 KB Output is correct
62 Correct 269 ms 173780 KB Output is correct
63 Correct 444 ms 175532 KB Output is correct
64 Correct 522 ms 175968 KB Output is correct
65 Correct 564 ms 173976 KB Output is correct
66 Correct 428 ms 168656 KB Output is correct
67 Correct 135 ms 150764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 141404 KB Output is correct
2 Correct 29 ms 137296 KB Output is correct
3 Correct 30 ms 137536 KB Output is correct
4 Correct 30 ms 141396 KB Output is correct
5 Correct 31 ms 141400 KB Output is correct
6 Correct 35 ms 141392 KB Output is correct
7 Correct 35 ms 137300 KB Output is correct
8 Correct 31 ms 141396 KB Output is correct
9 Correct 31 ms 141404 KB Output is correct
10 Correct 31 ms 141492 KB Output is correct
11 Correct 30 ms 137300 KB Output is correct
12 Correct 31 ms 141392 KB Output is correct
13 Correct 31 ms 141404 KB Output is correct
14 Correct 31 ms 141396 KB Output is correct
15 Correct 31 ms 141408 KB Output is correct
16 Correct 35 ms 141392 KB Output is correct
17 Correct 31 ms 141484 KB Output is correct
18 Correct 32 ms 141628 KB Output is correct
19 Correct 32 ms 141392 KB Output is correct
20 Correct 33 ms 141392 KB Output is correct
21 Correct 30 ms 141396 KB Output is correct
22 Correct 31 ms 141660 KB Output is correct
23 Correct 31 ms 141660 KB Output is correct
24 Correct 32 ms 141400 KB Output is correct
25 Correct 36 ms 141396 KB Output is correct
26 Correct 31 ms 141396 KB Output is correct
27 Correct 30 ms 141396 KB Output is correct
28 Correct 32 ms 141400 KB Output is correct
29 Correct 31 ms 141396 KB Output is correct
30 Correct 30 ms 141404 KB Output is correct
31 Correct 825 ms 176732 KB Output is correct
32 Correct 81 ms 144364 KB Output is correct
33 Correct 611 ms 173776 KB Output is correct
34 Correct 695 ms 173984 KB Output is correct
35 Correct 781 ms 176424 KB Output is correct
36 Correct 672 ms 176436 KB Output is correct
37 Correct 458 ms 168620 KB Output is correct
38 Correct 439 ms 168420 KB Output is correct
39 Correct 279 ms 161752 KB Output is correct
40 Correct 318 ms 163228 KB Output is correct
41 Correct 392 ms 165932 KB Output is correct
42 Correct 297 ms 166188 KB Output is correct
43 Correct 65 ms 144976 KB Output is correct
44 Correct 360 ms 165404 KB Output is correct
45 Correct 313 ms 161828 KB Output is correct
46 Correct 170 ms 156040 KB Output is correct
47 Correct 150 ms 155432 KB Output is correct
48 Correct 141 ms 154212 KB Output is correct
49 Correct 225 ms 157936 KB Output is correct
50 Correct 248 ms 164164 KB Output is correct
51 Correct 173 ms 156536 KB Output is correct
52 Correct 1052 ms 214872 KB Output is correct
53 Correct 1503 ms 209276 KB Output is correct
54 Correct 885 ms 226028 KB Output is correct
55 Correct 1002 ms 217068 KB Output is correct
56 Correct 1386 ms 208256 KB Output is correct
57 Correct 1482 ms 207780 KB Output is correct
58 Correct 707 ms 226068 KB Output is correct
59 Correct 808 ms 213404 KB Output is correct
60 Correct 855 ms 208760 KB Output is correct
61 Correct 941 ms 206144 KB Output is correct
62 Correct 713 ms 204912 KB Output is correct
63 Correct 745 ms 206284 KB Output is correct
64 Correct 4073 ms 266912 KB Output is correct
65 Correct 311 ms 165248 KB Output is correct
66 Correct 3680 ms 265364 KB Output is correct
67 Correct 827 ms 261168 KB Output is correct
68 Correct 1297 ms 261932 KB Output is correct
69 Correct 1206 ms 261360 KB Output is correct
70 Correct 3573 ms 264668 KB Output is correct
71 Correct 3541 ms 265532 KB Output is correct
72 Correct 1152 ms 267316 KB Output is correct
73 Correct 2891 ms 268144 KB Output is correct
74 Correct 3914 ms 266656 KB Output is correct
75 Correct 3641 ms 265128 KB Output is correct
76 Correct 1409 ms 227760 KB Output is correct
77 Correct 1393 ms 227632 KB Output is correct
78 Correct 1829 ms 240084 KB Output is correct
79 Correct 2309 ms 248672 KB Output is correct
80 Correct 2009 ms 245168 KB Output is correct
81 Correct 193 ms 169600 KB Output is correct
82 Correct 202 ms 165928 KB Output is correct
83 Correct 278 ms 176324 KB Output is correct
84 Correct 435 ms 173632 KB Output is correct
85 Correct 444 ms 175840 KB Output is correct
86 Correct 402 ms 168160 KB Output is correct
87 Correct 354 ms 170012 KB Output is correct
88 Correct 325 ms 171744 KB Output is correct
89 Correct 336 ms 167520 KB Output is correct
90 Correct 74 ms 151912 KB Output is correct
91 Correct 269 ms 173780 KB Output is correct
92 Correct 444 ms 175532 KB Output is correct
93 Correct 522 ms 175968 KB Output is correct
94 Correct 564 ms 173976 KB Output is correct
95 Correct 428 ms 168656 KB Output is correct
96 Correct 135 ms 150764 KB Output is correct
97 Correct 1206 ms 308284 KB Output is correct
98 Correct 306 ms 157988 KB Output is correct
99 Correct 4258 ms 315368 KB Output is correct
100 Correct 1208 ms 280604 KB Output is correct
101 Correct 1641 ms 332064 KB Output is correct
102 Correct 4895 ms 338176 KB Output is correct
103 Correct 3054 ms 291060 KB Output is correct
104 Correct 2864 ms 290448 KB Output is correct
105 Correct 1832 ms 257060 KB Output is correct
106 Correct 1996 ms 264736 KB Output is correct
107 Correct 2639 ms 308908 KB Output is correct
108 Correct 2850 ms 333372 KB Output is correct
109 Correct 2387 ms 275792 KB Output is correct
110 Correct 2039 ms 280640 KB Output is correct
111 Correct 2016 ms 292664 KB Output is correct
112 Correct 2021 ms 269140 KB Output is correct
113 Correct 243 ms 197544 KB Output is correct
114 Correct 1608 ms 298480 KB Output is correct
115 Correct 2926 ms 322356 KB Output is correct
116 Correct 3715 ms 318108 KB Output is correct
117 Correct 4145 ms 309232 KB Output is correct
118 Correct 2932 ms 278692 KB Output is correct
119 Correct 668 ms 177204 KB Output is correct
120 Correct 565 ms 189148 KB Output is correct
121 Correct 717 ms 199700 KB Output is correct
122 Correct 634 ms 192288 KB Output is correct
123 Correct 831 ms 210036 KB Output is correct
124 Correct 1194 ms 243168 KB Output is correct
125 Correct 783 ms 201924 KB Output is correct
126 Correct 1477 ms 260180 KB Output is correct