Submission #216347

# Submission time Handle Problem Language Result Execution time Memory
216347 2020-03-27T07:30:15 Z theStaticMind New Home (APIO18_new_home) C++14
12 / 100
5000 ms 53740 KB
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

struct X{
	int x, t, l, r;
};
struct Query{
	int x, t, id;
};

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k, q;
	cin >> n >> k >> q;

	vector<X> arr;
	vector<Query> Q;
	vector<int> ans(q, -1);

	for(int i = 0; i < n; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		arr.pb({a, b, c, d});
	}
	for(int i = 0; i < q; i++){
		int x, y;
		cin >> x >> y;
		Q.pb({x, y, i});
	}

	sort(all(arr), [&](X& a, X& b){return a.l < b.l;});
	sort(all(Q), [&](Query& a, Query& b){return a.t < b.t;});

	vector<int> Y;
	for(int i = 0; i < sz(arr); i++) Y.pb(i);

	sort(all(Y), [&](int x, int y){return arr[x].r < arr[y].r;});

	int a = 0, b = 0;

	multiset<int> data[k + 1];

	for(auto& c : Q){
		while(a < sz(arr) && arr[a].l <= c.t){
			data[arr[a].t].insert(arr[a].x);
			a++;
		}

		while(b < sz(Y) && arr[Y[b]].r < c.t){
			data[arr[Y[b]].t].erase(data[arr[Y[b]].t].find(arr[Y[b]].x));
			b++;
		}

		for(int i = 1; i <= k; i++){
			auto itr = data[i].upper_bound(c.x);
			
			int v = INF;

			if(itr != data[i].end()) v = *itr - c.x;
			if(!data[i].empty() && itr != data[i].begin()){ 
				itr--;
				v = min(v, c.x - *itr);
			}

			if(v == INF){
				ans[c.id] = -1;
				break;
			}
			else{
				ans[c.id] = max(ans[c.id], v);
			}

		}

	}

	for(int i = 0; i < q; i++) cout << ans[i] << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 2163 ms 10992 KB Output is correct
32 Correct 93 ms 7020 KB Output is correct
33 Correct 181 ms 8940 KB Output is correct
34 Correct 1679 ms 9452 KB Output is correct
35 Correct 969 ms 10836 KB Output is correct
36 Correct 231 ms 10860 KB Output is correct
37 Correct 174 ms 8940 KB Output is correct
38 Correct 114 ms 8812 KB Output is correct
39 Correct 103 ms 8944 KB Output is correct
40 Correct 97 ms 8936 KB Output is correct
41 Correct 309 ms 9196 KB Output is correct
42 Correct 245 ms 8940 KB Output is correct
43 Correct 311 ms 10364 KB Output is correct
44 Correct 258 ms 9156 KB Output is correct
45 Correct 129 ms 9068 KB Output is correct
46 Correct 79 ms 9068 KB Output is correct
47 Correct 80 ms 8560 KB Output is correct
48 Correct 73 ms 8684 KB Output is correct
49 Correct 92 ms 8812 KB Output is correct
50 Correct 209 ms 8872 KB Output is correct
51 Correct 83 ms 8860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5049 ms 53740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5064 ms 50616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 2163 ms 10992 KB Output is correct
32 Correct 93 ms 7020 KB Output is correct
33 Correct 181 ms 8940 KB Output is correct
34 Correct 1679 ms 9452 KB Output is correct
35 Correct 969 ms 10836 KB Output is correct
36 Correct 231 ms 10860 KB Output is correct
37 Correct 174 ms 8940 KB Output is correct
38 Correct 114 ms 8812 KB Output is correct
39 Correct 103 ms 8944 KB Output is correct
40 Correct 97 ms 8936 KB Output is correct
41 Correct 309 ms 9196 KB Output is correct
42 Correct 245 ms 8940 KB Output is correct
43 Correct 311 ms 10364 KB Output is correct
44 Correct 258 ms 9156 KB Output is correct
45 Correct 129 ms 9068 KB Output is correct
46 Correct 79 ms 9068 KB Output is correct
47 Correct 80 ms 8560 KB Output is correct
48 Correct 73 ms 8684 KB Output is correct
49 Correct 92 ms 8812 KB Output is correct
50 Correct 209 ms 8872 KB Output is correct
51 Correct 83 ms 8860 KB Output is correct
52 Correct 99 ms 13448 KB Output is correct
53 Correct 86 ms 11756 KB Output is correct
54 Correct 150 ms 11560 KB Output is correct
55 Execution timed out 5075 ms 9580 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 2163 ms 10992 KB Output is correct
32 Correct 93 ms 7020 KB Output is correct
33 Correct 181 ms 8940 KB Output is correct
34 Correct 1679 ms 9452 KB Output is correct
35 Correct 969 ms 10836 KB Output is correct
36 Correct 231 ms 10860 KB Output is correct
37 Correct 174 ms 8940 KB Output is correct
38 Correct 114 ms 8812 KB Output is correct
39 Correct 103 ms 8944 KB Output is correct
40 Correct 97 ms 8936 KB Output is correct
41 Correct 309 ms 9196 KB Output is correct
42 Correct 245 ms 8940 KB Output is correct
43 Correct 311 ms 10364 KB Output is correct
44 Correct 258 ms 9156 KB Output is correct
45 Correct 129 ms 9068 KB Output is correct
46 Correct 79 ms 9068 KB Output is correct
47 Correct 80 ms 8560 KB Output is correct
48 Correct 73 ms 8684 KB Output is correct
49 Correct 92 ms 8812 KB Output is correct
50 Correct 209 ms 8872 KB Output is correct
51 Correct 83 ms 8860 KB Output is correct
52 Execution timed out 5049 ms 53740 KB Time limit exceeded
53 Halted 0 ms 0 KB -