Submission #72003

# Submission time Handle Problem Language Result Execution time Memory
72003 2018-08-26T04:36:25 Z KLPP New Home (APIO18_new_home) C++14
12 / 100
5000 ms 95612 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
typedef long long int lld;
int abs(int x){
	if(x>0)return x;
	return -x;
}
int main(){
	int n,q,k;
	cin>>n>>k>>q;
	int stores[n][4];
	for(int i=0;i<n;i++){
		cin>>stores[i][0]>>stores[i][1]>>stores[i][2]>>stores[i][3];
		stores[i][1]--;
	}
	pair<int,pair<int,int> > queries[q];
	for(int i=0;i<q;i++){int x,y;
		cin>>x>>y;
		queries[i].second.second=i;
		queries[i].second.first=x;
		queries[i].first=y;
	}sort(queries,queries+q);
	
	pair<int,int> v[2*n];
	for(int i=0;i<n;i++){
		v[2*i]=pair<int,int>(stores[i][2],i);
		v[2*i+1]=pair<int,int>(stores[i][3]+1,i);
	}sort(v,v+2*n);
	int pos=0;
	bool used[n];
	for(int i=0;i<n;i++)used[i]=false;
	multiset<int> arr[k];
	int ans[q];
	for(int i=0;i<q;i++){
		while(pos<2*n && v[pos].first<=queries[i].first){
			if(used[v[pos].second]){
				used[v[pos].second]=false;
				int store=v[pos].second;
				std::multiset<int>::iterator it=arr[stores[store][1]].find(stores[store][0]);
				arr[stores[store][1]].erase(it);
			}else{
				used[v[pos].second]=true;
				int store=v[pos].second;
				arr[stores[store][1]].insert(stores[store][0]);
			}
			pos++;
		}
		int xcoord=queries[i].second.first;
		int number=queries[i].second.second;
		for(int j=0;j<k;j++){
			std::multiset<int>::iterator it=arr[j].upper_bound(xcoord);
			int R=1000000000;
			if(it!=arr[j].end()){
				R=min(R,abs(xcoord-*it));
			}
			if(it!=arr[j].begin()){
				it--;
				R=min(R,abs(xcoord-*it));
			}
			ans[number]=max(ans[number],R);
		}
	}
	for(int i=0;i<q;i++){
		if(ans[i]!=1000000000)cout<<ans[i]<<endl;
		else cout<<-1<<endl;
	}
		
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 5 ms 548 KB Output is correct
8 Correct 5 ms 548 KB Output is correct
9 Correct 7 ms 548 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 612 KB Output is correct
15 Correct 5 ms 612 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 4 ms 720 KB Output is correct
19 Correct 4 ms 720 KB Output is correct
20 Correct 5 ms 720 KB Output is correct
21 Correct 12 ms 720 KB Output is correct
22 Correct 6 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 6 ms 720 KB Output is correct
25 Correct 5 ms 720 KB Output is correct
26 Correct 6 ms 720 KB Output is correct
27 Correct 4 ms 720 KB Output is correct
28 Correct 5 ms 720 KB Output is correct
29 Correct 5 ms 720 KB Output is correct
30 Correct 6 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 5 ms 548 KB Output is correct
8 Correct 5 ms 548 KB Output is correct
9 Correct 7 ms 548 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 612 KB Output is correct
15 Correct 5 ms 612 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 4 ms 720 KB Output is correct
19 Correct 4 ms 720 KB Output is correct
20 Correct 5 ms 720 KB Output is correct
21 Correct 12 ms 720 KB Output is correct
22 Correct 6 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 6 ms 720 KB Output is correct
25 Correct 5 ms 720 KB Output is correct
26 Correct 6 ms 720 KB Output is correct
27 Correct 4 ms 720 KB Output is correct
28 Correct 5 ms 720 KB Output is correct
29 Correct 5 ms 720 KB Output is correct
30 Correct 6 ms 720 KB Output is correct
31 Correct 3340 ms 7428 KB Output is correct
32 Correct 335 ms 7428 KB Output is correct
33 Correct 437 ms 9392 KB Output is correct
34 Correct 2802 ms 12332 KB Output is correct
35 Correct 1946 ms 17004 KB Output is correct
36 Correct 649 ms 19940 KB Output is correct
37 Correct 392 ms 20192 KB Output is correct
38 Correct 301 ms 22828 KB Output is correct
39 Correct 315 ms 25628 KB Output is correct
40 Correct 331 ms 28600 KB Output is correct
41 Correct 561 ms 31672 KB Output is correct
42 Correct 688 ms 34456 KB Output is correct
43 Correct 674 ms 39828 KB Output is correct
44 Correct 535 ms 39888 KB Output is correct
45 Correct 406 ms 42736 KB Output is correct
46 Correct 320 ms 45616 KB Output is correct
47 Correct 298 ms 48092 KB Output is correct
48 Correct 342 ms 50864 KB Output is correct
49 Correct 318 ms 53656 KB Output is correct
50 Correct 519 ms 56680 KB Output is correct
51 Correct 317 ms 59504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5055 ms 92464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5098 ms 95612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 5 ms 548 KB Output is correct
8 Correct 5 ms 548 KB Output is correct
9 Correct 7 ms 548 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 612 KB Output is correct
15 Correct 5 ms 612 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 4 ms 720 KB Output is correct
19 Correct 4 ms 720 KB Output is correct
20 Correct 5 ms 720 KB Output is correct
21 Correct 12 ms 720 KB Output is correct
22 Correct 6 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 6 ms 720 KB Output is correct
25 Correct 5 ms 720 KB Output is correct
26 Correct 6 ms 720 KB Output is correct
27 Correct 4 ms 720 KB Output is correct
28 Correct 5 ms 720 KB Output is correct
29 Correct 5 ms 720 KB Output is correct
30 Correct 6 ms 720 KB Output is correct
31 Correct 3340 ms 7428 KB Output is correct
32 Correct 335 ms 7428 KB Output is correct
33 Correct 437 ms 9392 KB Output is correct
34 Correct 2802 ms 12332 KB Output is correct
35 Correct 1946 ms 17004 KB Output is correct
36 Correct 649 ms 19940 KB Output is correct
37 Correct 392 ms 20192 KB Output is correct
38 Correct 301 ms 22828 KB Output is correct
39 Correct 315 ms 25628 KB Output is correct
40 Correct 331 ms 28600 KB Output is correct
41 Correct 561 ms 31672 KB Output is correct
42 Correct 688 ms 34456 KB Output is correct
43 Correct 674 ms 39828 KB Output is correct
44 Correct 535 ms 39888 KB Output is correct
45 Correct 406 ms 42736 KB Output is correct
46 Correct 320 ms 45616 KB Output is correct
47 Correct 298 ms 48092 KB Output is correct
48 Correct 342 ms 50864 KB Output is correct
49 Correct 318 ms 53656 KB Output is correct
50 Correct 519 ms 56680 KB Output is correct
51 Correct 317 ms 59504 KB Output is correct
52 Execution timed out 5003 ms 95612 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 480 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 5 ms 548 KB Output is correct
8 Correct 5 ms 548 KB Output is correct
9 Correct 7 ms 548 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 612 KB Output is correct
15 Correct 5 ms 612 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 4 ms 720 KB Output is correct
19 Correct 4 ms 720 KB Output is correct
20 Correct 5 ms 720 KB Output is correct
21 Correct 12 ms 720 KB Output is correct
22 Correct 6 ms 720 KB Output is correct
23 Correct 5 ms 720 KB Output is correct
24 Correct 6 ms 720 KB Output is correct
25 Correct 5 ms 720 KB Output is correct
26 Correct 6 ms 720 KB Output is correct
27 Correct 4 ms 720 KB Output is correct
28 Correct 5 ms 720 KB Output is correct
29 Correct 5 ms 720 KB Output is correct
30 Correct 6 ms 720 KB Output is correct
31 Correct 3340 ms 7428 KB Output is correct
32 Correct 335 ms 7428 KB Output is correct
33 Correct 437 ms 9392 KB Output is correct
34 Correct 2802 ms 12332 KB Output is correct
35 Correct 1946 ms 17004 KB Output is correct
36 Correct 649 ms 19940 KB Output is correct
37 Correct 392 ms 20192 KB Output is correct
38 Correct 301 ms 22828 KB Output is correct
39 Correct 315 ms 25628 KB Output is correct
40 Correct 331 ms 28600 KB Output is correct
41 Correct 561 ms 31672 KB Output is correct
42 Correct 688 ms 34456 KB Output is correct
43 Correct 674 ms 39828 KB Output is correct
44 Correct 535 ms 39888 KB Output is correct
45 Correct 406 ms 42736 KB Output is correct
46 Correct 320 ms 45616 KB Output is correct
47 Correct 298 ms 48092 KB Output is correct
48 Correct 342 ms 50864 KB Output is correct
49 Correct 318 ms 53656 KB Output is correct
50 Correct 519 ms 56680 KB Output is correct
51 Correct 317 ms 59504 KB Output is correct
52 Execution timed out 5055 ms 92464 KB Time limit exceeded
53 Halted 0 ms 0 KB -