답안 #138807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138807 2019-07-30T10:52:03 Z FedericoS 새 집 (APIO18_new_home) C++14
12 / 100
5000 ms 93788 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){
 		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 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7672 KB Output is correct
7 Correct 11 ms 7648 KB Output is correct
8 Correct 11 ms 7648 KB Output is correct
9 Correct 12 ms 7548 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 10 ms 7544 KB Output is correct
12 Correct 10 ms 7672 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 7548 KB Output is correct
17 Correct 11 ms 7672 KB Output is correct
18 Correct 11 ms 7648 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7648 KB Output is correct
21 Correct 11 ms 7672 KB Output is correct
22 Correct 12 ms 7672 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7648 KB Output is correct
25 Correct 11 ms 7672 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7544 KB Output is correct
28 Correct 10 ms 7544 KB Output is correct
29 Correct 11 ms 7672 KB Output is correct
30 Correct 10 ms 7672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7672 KB Output is correct
7 Correct 11 ms 7648 KB Output is correct
8 Correct 11 ms 7648 KB Output is correct
9 Correct 12 ms 7548 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 10 ms 7544 KB Output is correct
12 Correct 10 ms 7672 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 7548 KB Output is correct
17 Correct 11 ms 7672 KB Output is correct
18 Correct 11 ms 7648 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7648 KB Output is correct
21 Correct 11 ms 7672 KB Output is correct
22 Correct 12 ms 7672 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7648 KB Output is correct
25 Correct 11 ms 7672 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7544 KB Output is correct
28 Correct 10 ms 7544 KB Output is correct
29 Correct 11 ms 7672 KB Output is correct
30 Correct 10 ms 7672 KB Output is correct
31 Correct 3224 ms 25684 KB Output is correct
32 Correct 273 ms 23640 KB Output is correct
33 Correct 463 ms 25688 KB Output is correct
34 Correct 2600 ms 25640 KB Output is correct
35 Correct 1602 ms 25560 KB Output is correct
36 Correct 506 ms 25560 KB Output is correct
37 Correct 429 ms 25560 KB Output is correct
38 Correct 346 ms 25768 KB Output is correct
39 Correct 336 ms 25564 KB Output is correct
40 Correct 327 ms 25708 KB Output is correct
41 Correct 560 ms 25692 KB Output is correct
42 Correct 683 ms 25616 KB Output is correct
43 Correct 684 ms 25048 KB Output is correct
44 Correct 505 ms 25688 KB Output is correct
45 Correct 387 ms 25688 KB Output is correct
46 Correct 316 ms 25560 KB Output is correct
47 Correct 314 ms 25428 KB Output is correct
48 Correct 304 ms 25432 KB Output is correct
49 Correct 319 ms 25560 KB Output is correct
50 Correct 483 ms 25688 KB Output is correct
51 Correct 307 ms 25432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2140 ms 88808 KB Output is correct
2 Correct 4428 ms 85608 KB Output is correct
3 Correct 1928 ms 93788 KB Output is correct
4 Correct 1955 ms 89356 KB Output is correct
5 Correct 2186 ms 85192 KB Output is correct
6 Correct 2963 ms 85564 KB Output is correct
7 Correct 1785 ms 93548 KB Output is correct
8 Correct 1936 ms 88288 KB Output is correct
9 Correct 1842 ms 87788 KB Output is correct
10 Execution timed out 5103 ms 84044 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1723 ms 87528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7672 KB Output is correct
7 Correct 11 ms 7648 KB Output is correct
8 Correct 11 ms 7648 KB Output is correct
9 Correct 12 ms 7548 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 10 ms 7544 KB Output is correct
12 Correct 10 ms 7672 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 7548 KB Output is correct
17 Correct 11 ms 7672 KB Output is correct
18 Correct 11 ms 7648 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7648 KB Output is correct
21 Correct 11 ms 7672 KB Output is correct
22 Correct 12 ms 7672 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7648 KB Output is correct
25 Correct 11 ms 7672 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7544 KB Output is correct
28 Correct 10 ms 7544 KB Output is correct
29 Correct 11 ms 7672 KB Output is correct
30 Correct 10 ms 7672 KB Output is correct
31 Correct 3224 ms 25684 KB Output is correct
32 Correct 273 ms 23640 KB Output is correct
33 Correct 463 ms 25688 KB Output is correct
34 Correct 2600 ms 25640 KB Output is correct
35 Correct 1602 ms 25560 KB Output is correct
36 Correct 506 ms 25560 KB Output is correct
37 Correct 429 ms 25560 KB Output is correct
38 Correct 346 ms 25768 KB Output is correct
39 Correct 336 ms 25564 KB Output is correct
40 Correct 327 ms 25708 KB Output is correct
41 Correct 560 ms 25692 KB Output is correct
42 Correct 683 ms 25616 KB Output is correct
43 Correct 684 ms 25048 KB Output is correct
44 Correct 505 ms 25688 KB Output is correct
45 Correct 387 ms 25688 KB Output is correct
46 Correct 316 ms 25560 KB Output is correct
47 Correct 314 ms 25428 KB Output is correct
48 Correct 304 ms 25432 KB Output is correct
49 Correct 319 ms 25560 KB Output is correct
50 Correct 483 ms 25688 KB Output is correct
51 Correct 307 ms 25432 KB Output is correct
52 Incorrect 355 ms 25456 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7672 KB Output is correct
7 Correct 11 ms 7648 KB Output is correct
8 Correct 11 ms 7648 KB Output is correct
9 Correct 12 ms 7548 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 10 ms 7544 KB Output is correct
12 Correct 10 ms 7672 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 7548 KB Output is correct
17 Correct 11 ms 7672 KB Output is correct
18 Correct 11 ms 7648 KB Output is correct
19 Correct 11 ms 7544 KB Output is correct
20 Correct 10 ms 7648 KB Output is correct
21 Correct 11 ms 7672 KB Output is correct
22 Correct 12 ms 7672 KB Output is correct
23 Correct 11 ms 7672 KB Output is correct
24 Correct 11 ms 7648 KB Output is correct
25 Correct 11 ms 7672 KB Output is correct
26 Correct 10 ms 7672 KB Output is correct
27 Correct 10 ms 7544 KB Output is correct
28 Correct 10 ms 7544 KB Output is correct
29 Correct 11 ms 7672 KB Output is correct
30 Correct 10 ms 7672 KB Output is correct
31 Correct 3224 ms 25684 KB Output is correct
32 Correct 273 ms 23640 KB Output is correct
33 Correct 463 ms 25688 KB Output is correct
34 Correct 2600 ms 25640 KB Output is correct
35 Correct 1602 ms 25560 KB Output is correct
36 Correct 506 ms 25560 KB Output is correct
37 Correct 429 ms 25560 KB Output is correct
38 Correct 346 ms 25768 KB Output is correct
39 Correct 336 ms 25564 KB Output is correct
40 Correct 327 ms 25708 KB Output is correct
41 Correct 560 ms 25692 KB Output is correct
42 Correct 683 ms 25616 KB Output is correct
43 Correct 684 ms 25048 KB Output is correct
44 Correct 505 ms 25688 KB Output is correct
45 Correct 387 ms 25688 KB Output is correct
46 Correct 316 ms 25560 KB Output is correct
47 Correct 314 ms 25428 KB Output is correct
48 Correct 304 ms 25432 KB Output is correct
49 Correct 319 ms 25560 KB Output is correct
50 Correct 483 ms 25688 KB Output is correct
51 Correct 307 ms 25432 KB Output is correct
52 Correct 2140 ms 88808 KB Output is correct
53 Correct 4428 ms 85608 KB Output is correct
54 Correct 1928 ms 93788 KB Output is correct
55 Correct 1955 ms 89356 KB Output is correct
56 Correct 2186 ms 85192 KB Output is correct
57 Correct 2963 ms 85564 KB Output is correct
58 Correct 1785 ms 93548 KB Output is correct
59 Correct 1936 ms 88288 KB Output is correct
60 Correct 1842 ms 87788 KB Output is correct
61 Execution timed out 5103 ms 84044 KB Time limit exceeded
62 Halted 0 ms 0 KB -