답안 #138808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138808 2019-07-30T10:53:42 Z FedericoS 새 집 (APIO18_new_home) C++14
22 / 100
3086 ms 88612 KB
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
 
int N,K,Q;
ll X[300005],T[300005],A[300005],B[300005],P[300005],Y[300005];
multiset<ll> L,R;
multiset<ll> S[405];
vector<ll> V[300005];
vector<pair<pair<ll,string>,pll> > Eold;
vector<pair<pair<ll,string>,ll> > E;
int ans[300005];

ll dist(ll x, ll t){
	ll res=1e9;
	auto p=S[t].lower_bound(x);
	if(p!=S[t].end())
		res=(*p)-x;
	if(p!=S[t].begin()){
		p--;
		res=min(res,x-(*p));
	}
	return res;
}

int main(){
	cin>>N>>K>>Q;
	for(int i=0;i<N;i++){
		cin>>X[i]>>T[i]>>A[i]>>B[i];
		T[i]--;
	}
	for(int i=0;i<Q;i++)
		cin>>P[i]>>Y[i];
 
	if(K<=400 and N<=60000){
 		for(int i=0;i<Q;i++)
 			E.push_back({{Y[i],"q"},i});
 		for(int i=0;i<N;i++){
 			E.push_back({{A[i],"a"},i});
 			E.push_back({{B[i],"r"},i});
 		}
 		sort(E.begin(),E.end());

 		for(auto p:E){
 			int a=p.second;
 			string t=p.first.second;

 			if(t=="a")
 				S[T[a]].insert(X[a]);
 			else if(t=="r")
 				S[T[a]].erase(S[T[a]].find(X[a]));
 			else{
 				ll res=-1;
 				for(int i=0;i<K;i++)
 					res=max(res,dist(P[a],i));
 				ans[a]=(res==1e9)?-1:res;
 			}

 		}

 		for(int i=0;i<Q;i++)
 			cout<<ans[i]<<" ";
	}
	else{
 
		for(int i=0;i<N;i++)
			X[i]*=2;
		for(int i=0;i<Q;i++)
			P[i]*=2;
 
		for(int i=0;i<Q;i++)
			Eold.push_back({{P[i],"cq"},{P[i],i}});
 
		for(int i=0;i<N;i++)
			V[T[i]].push_back(X[i]);
 
		for(int i=0;i<K;i++){
 
			sort(V[i].begin(),V[i].end());
 
			vector<int> W;
			for(ll x:V[i])
				if((!W.empty() and W.back()!=x) or W.empty())
					W.push_back(x);
 
			V[i].clear();
			for(ll x:W)
				V[i].push_back(x);
		}
 
		for(int i=0;i<K;i++)
			for(int x:V[i])
				Eold.push_back({{x,"arl"},{x,x}});
 
		for(int i=0;i<K;i++)
			for(int j=0;j<V[i].size()-1;j++)
				if(V[i][j]!=V[i][j+1])
					Eold.push_back({{(V[i][j]+V[i][j+1])/2,"blr"},{V[i][j],V[i][j+1]}});
 
		for(int i=0;i<K;i++)
			R.insert(V[i][0]);
 
		sort(Eold.begin(),Eold.end());
 
		//for(auto p:Eold)cout<<p.first.first<<" "<<p.first.second<<" "<<p.second.first<<" "<<p.second.second<<endl;		
 
		for(auto p:Eold){
 
			ll a=p.second.first;
			ll b=p.second.second;
			string t=p.first.second;
 
			if(t=="blr"){
				L.erase(L.find(a));
				R.insert(b);
			}
			else if(t=="arl"){
				R.erase(R.find(a));
				L.insert(b);
			}
			else{
				ll x=0,y=0;
				if(!L.empty())
					x=a-*L.begin();
				if(!R.empty())
					y=*R.rbegin()-a;
				ans[b]=max(x,y);
			}
		}
 
		for(int i=0;i<Q;i++)
			cout<<ans[i]/2<<" ";
	}
 
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:100:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<V[i].size()-1;j++)
                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 10 ms 7420 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 10 ms 7548 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 11 ms 7672 KB Output is correct
9 Correct 12 ms 7672 KB Output is correct
10 Correct 10 ms 7672 KB Output is correct
11 Correct 11 ms 7672 KB Output is correct
12 Correct 10 ms 7676 KB Output is correct
13 Correct 10 ms 7672 KB Output is correct
14 Correct 10 ms 7672 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 11 ms 7644 KB Output is correct
17 Correct 10 ms 7544 KB Output is correct
18 Correct 10 ms 7672 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7672 KB Output is correct
21 Correct 11 ms 7544 KB Output is correct
22 Correct 12 ms 7644 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7672 KB Output is correct
25 Correct 11 ms 7716 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7672 KB Output is correct
28 Correct 10 ms 7672 KB Output is correct
29 Correct 10 ms 7672 KB Output is correct
30 Correct 10 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 10 ms 7420 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 10 ms 7548 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 11 ms 7672 KB Output is correct
9 Correct 12 ms 7672 KB Output is correct
10 Correct 10 ms 7672 KB Output is correct
11 Correct 11 ms 7672 KB Output is correct
12 Correct 10 ms 7676 KB Output is correct
13 Correct 10 ms 7672 KB Output is correct
14 Correct 10 ms 7672 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 11 ms 7644 KB Output is correct
17 Correct 10 ms 7544 KB Output is correct
18 Correct 10 ms 7672 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7672 KB Output is correct
21 Correct 11 ms 7544 KB Output is correct
22 Correct 12 ms 7644 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7672 KB Output is correct
25 Correct 11 ms 7716 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7672 KB Output is correct
28 Correct 10 ms 7672 KB Output is correct
29 Correct 10 ms 7672 KB Output is correct
30 Correct 10 ms 7544 KB Output is correct
31 Correct 3086 ms 22760 KB Output is correct
32 Correct 278 ms 22680 KB Output is correct
33 Correct 469 ms 22696 KB Output is correct
34 Correct 2489 ms 22744 KB Output is correct
35 Correct 1543 ms 22732 KB Output is correct
36 Correct 490 ms 22744 KB Output is correct
37 Correct 423 ms 22832 KB Output is correct
38 Correct 342 ms 22744 KB Output is correct
39 Correct 323 ms 22752 KB Output is correct
40 Correct 323 ms 22744 KB Output is correct
41 Correct 559 ms 22744 KB Output is correct
42 Correct 685 ms 22764 KB Output is correct
43 Correct 676 ms 22744 KB Output is correct
44 Correct 512 ms 22716 KB Output is correct
45 Correct 369 ms 22744 KB Output is correct
46 Correct 312 ms 22744 KB Output is correct
47 Correct 300 ms 22620 KB Output is correct
48 Correct 315 ms 22652 KB Output is correct
49 Correct 317 ms 22660 KB Output is correct
50 Correct 488 ms 22740 KB Output is correct
51 Correct 310 ms 22744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2084 ms 83620 KB Output is correct
2 Correct 1511 ms 82000 KB Output is correct
3 Correct 1932 ms 88612 KB Output is correct
4 Correct 1985 ms 83984 KB Output is correct
5 Correct 1478 ms 85424 KB Output is correct
6 Correct 1513 ms 81928 KB Output is correct
7 Correct 1877 ms 88600 KB Output is correct
8 Correct 1918 ms 83084 KB Output is correct
9 Correct 1814 ms 82596 KB Output is correct
10 Correct 1610 ms 82408 KB Output is correct
11 Correct 1553 ms 86564 KB Output is correct
12 Correct 1556 ms 87128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1728 ms 82632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 10 ms 7420 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 10 ms 7548 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 11 ms 7672 KB Output is correct
9 Correct 12 ms 7672 KB Output is correct
10 Correct 10 ms 7672 KB Output is correct
11 Correct 11 ms 7672 KB Output is correct
12 Correct 10 ms 7676 KB Output is correct
13 Correct 10 ms 7672 KB Output is correct
14 Correct 10 ms 7672 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 11 ms 7644 KB Output is correct
17 Correct 10 ms 7544 KB Output is correct
18 Correct 10 ms 7672 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7672 KB Output is correct
21 Correct 11 ms 7544 KB Output is correct
22 Correct 12 ms 7644 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7672 KB Output is correct
25 Correct 11 ms 7716 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7672 KB Output is correct
28 Correct 10 ms 7672 KB Output is correct
29 Correct 10 ms 7672 KB Output is correct
30 Correct 10 ms 7544 KB Output is correct
31 Correct 3086 ms 22760 KB Output is correct
32 Correct 278 ms 22680 KB Output is correct
33 Correct 469 ms 22696 KB Output is correct
34 Correct 2489 ms 22744 KB Output is correct
35 Correct 1543 ms 22732 KB Output is correct
36 Correct 490 ms 22744 KB Output is correct
37 Correct 423 ms 22832 KB Output is correct
38 Correct 342 ms 22744 KB Output is correct
39 Correct 323 ms 22752 KB Output is correct
40 Correct 323 ms 22744 KB Output is correct
41 Correct 559 ms 22744 KB Output is correct
42 Correct 685 ms 22764 KB Output is correct
43 Correct 676 ms 22744 KB Output is correct
44 Correct 512 ms 22716 KB Output is correct
45 Correct 369 ms 22744 KB Output is correct
46 Correct 312 ms 22744 KB Output is correct
47 Correct 300 ms 22620 KB Output is correct
48 Correct 315 ms 22652 KB Output is correct
49 Correct 317 ms 22660 KB Output is correct
50 Correct 488 ms 22740 KB Output is correct
51 Correct 310 ms 22744 KB Output is correct
52 Incorrect 362 ms 22360 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 10 ms 7420 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 10 ms 7548 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 11 ms 7672 KB Output is correct
9 Correct 12 ms 7672 KB Output is correct
10 Correct 10 ms 7672 KB Output is correct
11 Correct 11 ms 7672 KB Output is correct
12 Correct 10 ms 7676 KB Output is correct
13 Correct 10 ms 7672 KB Output is correct
14 Correct 10 ms 7672 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 11 ms 7644 KB Output is correct
17 Correct 10 ms 7544 KB Output is correct
18 Correct 10 ms 7672 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7672 KB Output is correct
21 Correct 11 ms 7544 KB Output is correct
22 Correct 12 ms 7644 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7672 KB Output is correct
25 Correct 11 ms 7716 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7672 KB Output is correct
28 Correct 10 ms 7672 KB Output is correct
29 Correct 10 ms 7672 KB Output is correct
30 Correct 10 ms 7544 KB Output is correct
31 Correct 3086 ms 22760 KB Output is correct
32 Correct 278 ms 22680 KB Output is correct
33 Correct 469 ms 22696 KB Output is correct
34 Correct 2489 ms 22744 KB Output is correct
35 Correct 1543 ms 22732 KB Output is correct
36 Correct 490 ms 22744 KB Output is correct
37 Correct 423 ms 22832 KB Output is correct
38 Correct 342 ms 22744 KB Output is correct
39 Correct 323 ms 22752 KB Output is correct
40 Correct 323 ms 22744 KB Output is correct
41 Correct 559 ms 22744 KB Output is correct
42 Correct 685 ms 22764 KB Output is correct
43 Correct 676 ms 22744 KB Output is correct
44 Correct 512 ms 22716 KB Output is correct
45 Correct 369 ms 22744 KB Output is correct
46 Correct 312 ms 22744 KB Output is correct
47 Correct 300 ms 22620 KB Output is correct
48 Correct 315 ms 22652 KB Output is correct
49 Correct 317 ms 22660 KB Output is correct
50 Correct 488 ms 22740 KB Output is correct
51 Correct 310 ms 22744 KB Output is correct
52 Correct 2084 ms 83620 KB Output is correct
53 Correct 1511 ms 82000 KB Output is correct
54 Correct 1932 ms 88612 KB Output is correct
55 Correct 1985 ms 83984 KB Output is correct
56 Correct 1478 ms 85424 KB Output is correct
57 Correct 1513 ms 81928 KB Output is correct
58 Correct 1877 ms 88600 KB Output is correct
59 Correct 1918 ms 83084 KB Output is correct
60 Correct 1814 ms 82596 KB Output is correct
61 Correct 1610 ms 82408 KB Output is correct
62 Correct 1553 ms 86564 KB Output is correct
63 Correct 1556 ms 87128 KB Output is correct
64 Incorrect 1728 ms 82632 KB Output isn't correct
65 Halted 0 ms 0 KB -