Submission #94798

# Submission time Handle Problem Language Result Execution time Memory
94798 2019-01-24T05:30:05 Z jangwonyoung New Home (APIO18_new_home) C++14
80 / 100
5000 ms 259348 KB
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=3e5+1,Q=3e5+1,K=3e5+1;
int n,k,q;
struct pt{
	ll x,tp,t;//<0: add, =0: qry, >0: rmv
};
bool operator<(pt x,pt y){
	return x.t<y.t;
}
pt a[2*N];
multiset<ll>s[K];
int mptr=0;
vector<int>bin[3*N];
map<pair<ll,ll>,int>mp;//should clear after inserting all stores :)
struct upd{
	ll x,l,r,pos;
};
bool operator<(upd x,upd y){
	return x.pos<y.pos;
}
vector<upd>pve,nve;
string f(ll x){
	string ret;
	if(x<=-1e8) return "-inf";
	if(x>=1e8) return "inf";
	if(x==0) ret+='0';
	while(x>0){
		char c=x%10+48;
		x/=10;
		ret=c+ret;
	}
	return ret;
}
void add(ll xl,ll xr,ll t){
	int num=mp[{xl,xr}];
	if(num==0) mp[{xl,xr}]=num=++mptr;
	bin[num].push_back(t);
}
void rmv(ll xl,ll xr,ll t){
	int cur=mp[{xl,xr}];
	ll p=bin[cur].back();
	bin[cur].pop_back();
	if(p==t) return;t--;
	upd pl={-xl,p,t,-(xl+xr)/2};
	upd nl={xr,p,t,(xl+xr+1)/2};
	pve.push_back(pl);nve.push_back(nl);
}
ll ans[Q];
pair<pair<ll,ll>,int>b[Q];
pair<ll,ll>c[Q];
ll st[1<<20];
void init(int id,int l,int r){
	st[id]=-1e9;
	if(l==r) return;
	int mid=(l+r)/2;
	init(id*2,l,mid);init(id*2+1,mid+1,r);
}
void upd(int id,int l,int r,int ql,int qr,ll v){
	if(l>qr || r<ql) return;
	if(ql<=l && r<=qr){
		st[id]=max(st[id],v);
		return;
	}
	int mid=(l+r)/2;
	upd(id*2,l,mid,ql,qr,v);
	upd(id*2+1,mid+1,r,ql,qr,v);
}
ll qry(int id,int l,int r,int p){
	if(l==r) return st[id];
	int mid=(l+r)/2;
	if(p<=mid) return max(st[id],qry(id*2,l,mid,p));
	else return max(st[id],qry(id*2+1,mid+1,r,p));
}
void in(int& x){
	char c=getchar();
	while(c<48 || c>57) c=getchar();
	x=0;
	while(c>=48 && c<=57){
		x=x*10+c-48;
		c=getchar();
	}
}
void in(ll& x){
	char c=getchar();
	while(c<48 || c>57) c=getchar();
	x=0;
	while(c>=48 && c<=57){
		x=x*10+c-48;
		c=getchar();
	}
}
int main(){
	ios::sync_with_stdio(false);
	in(n);in(k);in(q);
	for(int i=1; i<=3*n ;i++) bin[i].reserve(2);
	for(int i=1; i<=n ;i++){
		ll x,tp,u,v;in(x);in(tp);in(u);in(v);
		a[i*2-1]={x,-tp,u};
		a[i*2]={x,tp,v+1};
	}
	mptr=1;
	for(int i=1; i<=k ;i++){
		s[i].insert(-1e9);
		s[i].insert(1e9);
		mp[{(ll)-1e9,(ll)1e9}]=mptr;
		bin[mptr].push_back(1);
	}
	sort(a+1,a+2*n+1);
	for(int i=1; i<=2*n ;i++){
		ll x=a[i].x,tp=a[i].tp,t=a[i].t;
		if(tp<0){
			tp=-tp;
			auto it=s[tp].lower_bound(x);
			auto it2=it;--it2;
			rmv(*it2,*it,t);add(*it2,x,t);add(x,*it,t);
			s[tp].insert(x);
		}
		else{
			auto it3=s[tp].lower_bound(x);
			auto it=it3;++it;
			auto it2=it3;--it2;
			rmv(*it2,x,t);rmv(x,*it,t);add(*it2,*it,t);
			s[tp].erase(it3);
		}
	}
	for(int i=1; i<=k ;i++) rmv(-1e9,1e9,1e9);
	sort(nve.begin(),nve.end());
	sort(pve.begin(),pve.end());
	for(int i=1; i<=q ;i++){
		in(b[i].fi.fi);in(b[i].fi.se);
		b[i].se=i;
		c[i]={b[i].fi.se,i};
	}
	sort(c+1,c+q+1);
	for(int i=1; i<=q ;i++) b[c[i].se].fi.se=i;
	sort(b+1,b+q+1);
	int ptr=0;
	init(1,1,q);
	for(int i=1; i<=q ;i++){
		while(ptr<nve.size() && nve[ptr].pos<=b[i].fi.fi){
			int l=lower_bound(c+1,c+q+1,(pair<ll,ll>){nve[ptr].l,0LL})-c;
			int r=lower_bound(c+1,c+q+1,(pair<ll,ll>){nve[ptr].r+1,0LL})-c-1;
			if(l<=r) upd(1,1,q,l,r,nve[ptr].x);
			ptr++;
		}
		ans[b[i].se]=max(ans[b[i].se],qry(1,1,q,b[i].fi.se)-b[i].fi.fi);
	}
	init(1,1,q);
	reverse(b+1,b+q+1);
	for(int i=1; i<=q ;i++) b[i].fi.fi=-b[i].fi.fi;
	ptr=0;
	for(int i=1; i<=q ;i++){
		while(ptr<pve.size() && pve[ptr].pos<=b[i].fi.fi){
			int l=lower_bound(c+1,c+q+1,(pair<ll,ll>){pve[ptr].l,0LL})-c;
			int r=lower_bound(c+1,c+q+1,(pair<ll,ll>){pve[ptr].r+1,0LL})-c-1;
			if(l<=r) upd(1,1,q,l,r,pve[ptr].x);
			ptr++;
		}
		ans[b[i].se]=max(ans[b[i].se],qry(1,1,q,b[i].fi.se)-b[i].fi.fi);
	}
	for(int i=1; i<=q ;i++){
		if(ans[i]>=(ll)1e8) cout << "-1\n";
		else cout << ans[i] << '\n';
	}
}

Compilation message

new_home.cpp: In function 'void rmv(ll, ll, ll)':
new_home.cpp:51:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(p==t) return;t--;
  ^~
new_home.cpp:51:18: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(p==t) return;t--;
                  ^
new_home.cpp: In function 'int main()':
new_home.cpp:148:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(ptr<nve.size() && nve[ptr].pos<=b[i].fi.fi){
         ~~~^~~~~~~~~~~
new_home.cpp:161:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(ptr<pve.size() && pve[ptr].pos<=b[i].fi.fi){
         ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 35576 KB Output is correct
2 Correct 28 ms 35576 KB Output is correct
3 Correct 30 ms 35580 KB Output is correct
4 Correct 28 ms 35624 KB Output is correct
5 Correct 29 ms 35836 KB Output is correct
6 Correct 31 ms 35964 KB Output is correct
7 Correct 37 ms 35960 KB Output is correct
8 Correct 36 ms 35960 KB Output is correct
9 Correct 35 ms 36132 KB Output is correct
10 Correct 36 ms 35960 KB Output is correct
11 Correct 35 ms 35836 KB Output is correct
12 Correct 36 ms 35960 KB Output is correct
13 Correct 35 ms 35964 KB Output is correct
14 Correct 40 ms 35960 KB Output is correct
15 Correct 36 ms 35960 KB Output is correct
16 Correct 36 ms 35964 KB Output is correct
17 Correct 36 ms 35960 KB Output is correct
18 Correct 35 ms 35960 KB Output is correct
19 Correct 35 ms 35960 KB Output is correct
20 Correct 36 ms 35960 KB Output is correct
21 Correct 35 ms 35960 KB Output is correct
22 Correct 36 ms 35960 KB Output is correct
23 Correct 33 ms 35960 KB Output is correct
24 Correct 30 ms 35932 KB Output is correct
25 Correct 30 ms 35960 KB Output is correct
26 Correct 31 ms 35960 KB Output is correct
27 Correct 36 ms 35960 KB Output is correct
28 Correct 35 ms 35832 KB Output is correct
29 Correct 36 ms 35832 KB Output is correct
30 Correct 36 ms 35832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 35576 KB Output is correct
2 Correct 28 ms 35576 KB Output is correct
3 Correct 30 ms 35580 KB Output is correct
4 Correct 28 ms 35624 KB Output is correct
5 Correct 29 ms 35836 KB Output is correct
6 Correct 31 ms 35964 KB Output is correct
7 Correct 37 ms 35960 KB Output is correct
8 Correct 36 ms 35960 KB Output is correct
9 Correct 35 ms 36132 KB Output is correct
10 Correct 36 ms 35960 KB Output is correct
11 Correct 35 ms 35836 KB Output is correct
12 Correct 36 ms 35960 KB Output is correct
13 Correct 35 ms 35964 KB Output is correct
14 Correct 40 ms 35960 KB Output is correct
15 Correct 36 ms 35960 KB Output is correct
16 Correct 36 ms 35964 KB Output is correct
17 Correct 36 ms 35960 KB Output is correct
18 Correct 35 ms 35960 KB Output is correct
19 Correct 35 ms 35960 KB Output is correct
20 Correct 36 ms 35960 KB Output is correct
21 Correct 35 ms 35960 KB Output is correct
22 Correct 36 ms 35960 KB Output is correct
23 Correct 33 ms 35960 KB Output is correct
24 Correct 30 ms 35932 KB Output is correct
25 Correct 30 ms 35960 KB Output is correct
26 Correct 31 ms 35960 KB Output is correct
27 Correct 36 ms 35960 KB Output is correct
28 Correct 35 ms 35832 KB Output is correct
29 Correct 36 ms 35832 KB Output is correct
30 Correct 36 ms 35832 KB Output is correct
31 Correct 810 ms 76356 KB Output is correct
32 Correct 159 ms 52008 KB Output is correct
33 Correct 733 ms 73992 KB Output is correct
34 Correct 701 ms 74228 KB Output is correct
35 Correct 764 ms 76032 KB Output is correct
36 Correct 818 ms 76068 KB Output is correct
37 Correct 511 ms 73264 KB Output is correct
38 Correct 462 ms 73124 KB Output is correct
39 Correct 386 ms 72984 KB Output is correct
40 Correct 395 ms 73000 KB Output is correct
41 Correct 553 ms 74156 KB Output is correct
42 Correct 559 ms 73932 KB Output is correct
43 Correct 127 ms 57924 KB Output is correct
44 Correct 550 ms 74076 KB Output is correct
45 Correct 485 ms 73972 KB Output is correct
46 Correct 451 ms 73904 KB Output is correct
47 Correct 275 ms 71576 KB Output is correct
48 Correct 304 ms 71464 KB Output is correct
49 Correct 318 ms 72624 KB Output is correct
50 Correct 352 ms 73124 KB Output is correct
51 Correct 340 ms 72612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3072 ms 197768 KB Output is correct
2 Correct 2986 ms 188536 KB Output is correct
3 Correct 2704 ms 246588 KB Output is correct
4 Correct 3190 ms 204824 KB Output is correct
5 Correct 3042 ms 188444 KB Output is correct
6 Correct 3200 ms 188772 KB Output is correct
7 Correct 2060 ms 246664 KB Output is correct
8 Correct 2345 ms 207384 KB Output is correct
9 Correct 2195 ms 196012 KB Output is correct
10 Correct 2481 ms 191032 KB Output is correct
11 Correct 1489 ms 188484 KB Output is correct
12 Correct 1809 ms 190736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4543 ms 211596 KB Output is correct
2 Correct 921 ms 139352 KB Output is correct
3 Correct 4677 ms 209836 KB Output is correct
4 Correct 2845 ms 244660 KB Output is correct
5 Correct 4443 ms 213780 KB Output is correct
6 Correct 3952 ms 217756 KB Output is correct
7 Correct 3941 ms 209764 KB Output is correct
8 Correct 4418 ms 210308 KB Output is correct
9 Correct 2729 ms 246080 KB Output is correct
10 Correct 3495 ms 212844 KB Output is correct
11 Correct 4006 ms 210488 KB Output is correct
12 Correct 4403 ms 208732 KB Output is correct
13 Correct 1709 ms 203168 KB Output is correct
14 Correct 1649 ms 201328 KB Output is correct
15 Correct 2003 ms 205412 KB Output is correct
16 Correct 2365 ms 207724 KB Output is correct
17 Correct 2249 ms 204420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 35576 KB Output is correct
2 Correct 28 ms 35576 KB Output is correct
3 Correct 30 ms 35580 KB Output is correct
4 Correct 28 ms 35624 KB Output is correct
5 Correct 29 ms 35836 KB Output is correct
6 Correct 31 ms 35964 KB Output is correct
7 Correct 37 ms 35960 KB Output is correct
8 Correct 36 ms 35960 KB Output is correct
9 Correct 35 ms 36132 KB Output is correct
10 Correct 36 ms 35960 KB Output is correct
11 Correct 35 ms 35836 KB Output is correct
12 Correct 36 ms 35960 KB Output is correct
13 Correct 35 ms 35964 KB Output is correct
14 Correct 40 ms 35960 KB Output is correct
15 Correct 36 ms 35960 KB Output is correct
16 Correct 36 ms 35964 KB Output is correct
17 Correct 36 ms 35960 KB Output is correct
18 Correct 35 ms 35960 KB Output is correct
19 Correct 35 ms 35960 KB Output is correct
20 Correct 36 ms 35960 KB Output is correct
21 Correct 35 ms 35960 KB Output is correct
22 Correct 36 ms 35960 KB Output is correct
23 Correct 33 ms 35960 KB Output is correct
24 Correct 30 ms 35932 KB Output is correct
25 Correct 30 ms 35960 KB Output is correct
26 Correct 31 ms 35960 KB Output is correct
27 Correct 36 ms 35960 KB Output is correct
28 Correct 35 ms 35832 KB Output is correct
29 Correct 36 ms 35832 KB Output is correct
30 Correct 36 ms 35832 KB Output is correct
31 Correct 810 ms 76356 KB Output is correct
32 Correct 159 ms 52008 KB Output is correct
33 Correct 733 ms 73992 KB Output is correct
34 Correct 701 ms 74228 KB Output is correct
35 Correct 764 ms 76032 KB Output is correct
36 Correct 818 ms 76068 KB Output is correct
37 Correct 511 ms 73264 KB Output is correct
38 Correct 462 ms 73124 KB Output is correct
39 Correct 386 ms 72984 KB Output is correct
40 Correct 395 ms 73000 KB Output is correct
41 Correct 553 ms 74156 KB Output is correct
42 Correct 559 ms 73932 KB Output is correct
43 Correct 127 ms 57924 KB Output is correct
44 Correct 550 ms 74076 KB Output is correct
45 Correct 485 ms 73972 KB Output is correct
46 Correct 451 ms 73904 KB Output is correct
47 Correct 275 ms 71576 KB Output is correct
48 Correct 304 ms 71464 KB Output is correct
49 Correct 318 ms 72624 KB Output is correct
50 Correct 352 ms 73124 KB Output is correct
51 Correct 340 ms 72612 KB Output is correct
52 Correct 517 ms 82488 KB Output is correct
53 Correct 515 ms 80596 KB Output is correct
54 Correct 663 ms 77868 KB Output is correct
55 Correct 518 ms 77104 KB Output is correct
56 Correct 531 ms 78392 KB Output is correct
57 Correct 543 ms 74992 KB Output is correct
58 Correct 566 ms 76884 KB Output is correct
59 Correct 582 ms 78268 KB Output is correct
60 Correct 560 ms 74968 KB Output is correct
61 Correct 163 ms 71652 KB Output is correct
62 Correct 544 ms 82608 KB Output is correct
63 Correct 619 ms 79152 KB Output is correct
64 Correct 673 ms 77752 KB Output is correct
65 Correct 642 ms 75372 KB Output is correct
66 Correct 597 ms 74080 KB Output is correct
67 Correct 214 ms 56264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 35576 KB Output is correct
2 Correct 28 ms 35576 KB Output is correct
3 Correct 30 ms 35580 KB Output is correct
4 Correct 28 ms 35624 KB Output is correct
5 Correct 29 ms 35836 KB Output is correct
6 Correct 31 ms 35964 KB Output is correct
7 Correct 37 ms 35960 KB Output is correct
8 Correct 36 ms 35960 KB Output is correct
9 Correct 35 ms 36132 KB Output is correct
10 Correct 36 ms 35960 KB Output is correct
11 Correct 35 ms 35836 KB Output is correct
12 Correct 36 ms 35960 KB Output is correct
13 Correct 35 ms 35964 KB Output is correct
14 Correct 40 ms 35960 KB Output is correct
15 Correct 36 ms 35960 KB Output is correct
16 Correct 36 ms 35964 KB Output is correct
17 Correct 36 ms 35960 KB Output is correct
18 Correct 35 ms 35960 KB Output is correct
19 Correct 35 ms 35960 KB Output is correct
20 Correct 36 ms 35960 KB Output is correct
21 Correct 35 ms 35960 KB Output is correct
22 Correct 36 ms 35960 KB Output is correct
23 Correct 33 ms 35960 KB Output is correct
24 Correct 30 ms 35932 KB Output is correct
25 Correct 30 ms 35960 KB Output is correct
26 Correct 31 ms 35960 KB Output is correct
27 Correct 36 ms 35960 KB Output is correct
28 Correct 35 ms 35832 KB Output is correct
29 Correct 36 ms 35832 KB Output is correct
30 Correct 36 ms 35832 KB Output is correct
31 Correct 810 ms 76356 KB Output is correct
32 Correct 159 ms 52008 KB Output is correct
33 Correct 733 ms 73992 KB Output is correct
34 Correct 701 ms 74228 KB Output is correct
35 Correct 764 ms 76032 KB Output is correct
36 Correct 818 ms 76068 KB Output is correct
37 Correct 511 ms 73264 KB Output is correct
38 Correct 462 ms 73124 KB Output is correct
39 Correct 386 ms 72984 KB Output is correct
40 Correct 395 ms 73000 KB Output is correct
41 Correct 553 ms 74156 KB Output is correct
42 Correct 559 ms 73932 KB Output is correct
43 Correct 127 ms 57924 KB Output is correct
44 Correct 550 ms 74076 KB Output is correct
45 Correct 485 ms 73972 KB Output is correct
46 Correct 451 ms 73904 KB Output is correct
47 Correct 275 ms 71576 KB Output is correct
48 Correct 304 ms 71464 KB Output is correct
49 Correct 318 ms 72624 KB Output is correct
50 Correct 352 ms 73124 KB Output is correct
51 Correct 340 ms 72612 KB Output is correct
52 Correct 3072 ms 197768 KB Output is correct
53 Correct 2986 ms 188536 KB Output is correct
54 Correct 2704 ms 246588 KB Output is correct
55 Correct 3190 ms 204824 KB Output is correct
56 Correct 3042 ms 188444 KB Output is correct
57 Correct 3200 ms 188772 KB Output is correct
58 Correct 2060 ms 246664 KB Output is correct
59 Correct 2345 ms 207384 KB Output is correct
60 Correct 2195 ms 196012 KB Output is correct
61 Correct 2481 ms 191032 KB Output is correct
62 Correct 1489 ms 188484 KB Output is correct
63 Correct 1809 ms 190736 KB Output is correct
64 Correct 4543 ms 211596 KB Output is correct
65 Correct 921 ms 139352 KB Output is correct
66 Correct 4677 ms 209836 KB Output is correct
67 Correct 2845 ms 244660 KB Output is correct
68 Correct 4443 ms 213780 KB Output is correct
69 Correct 3952 ms 217756 KB Output is correct
70 Correct 3941 ms 209764 KB Output is correct
71 Correct 4418 ms 210308 KB Output is correct
72 Correct 2729 ms 246080 KB Output is correct
73 Correct 3495 ms 212844 KB Output is correct
74 Correct 4006 ms 210488 KB Output is correct
75 Correct 4403 ms 208732 KB Output is correct
76 Correct 1709 ms 203168 KB Output is correct
77 Correct 1649 ms 201328 KB Output is correct
78 Correct 2003 ms 205412 KB Output is correct
79 Correct 2365 ms 207724 KB Output is correct
80 Correct 2249 ms 204420 KB Output is correct
81 Correct 517 ms 82488 KB Output is correct
82 Correct 515 ms 80596 KB Output is correct
83 Correct 663 ms 77868 KB Output is correct
84 Correct 518 ms 77104 KB Output is correct
85 Correct 531 ms 78392 KB Output is correct
86 Correct 543 ms 74992 KB Output is correct
87 Correct 566 ms 76884 KB Output is correct
88 Correct 582 ms 78268 KB Output is correct
89 Correct 560 ms 74968 KB Output is correct
90 Correct 163 ms 71652 KB Output is correct
91 Correct 544 ms 82608 KB Output is correct
92 Correct 619 ms 79152 KB Output is correct
93 Correct 673 ms 77752 KB Output is correct
94 Correct 642 ms 75372 KB Output is correct
95 Correct 597 ms 74080 KB Output is correct
96 Correct 214 ms 56264 KB Output is correct
97 Correct 3570 ms 259348 KB Output is correct
98 Correct 847 ms 118552 KB Output is correct
99 Execution timed out 5077 ms 216076 KB Time limit exceeded
100 Halted 0 ms 0 KB -