Submission #673286

# Submission time Handle Problem Language Result Execution time Memory
673286 2022-12-20T05:50:32 Z Dan4Life New Home (APIO18_new_home) C++17
12 / 100
5000 ms 83816 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long 
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
using ll = long long;
const int maxn = (int)3e5+10;
const ll LINF = (ll)2e18;
struct store{
	int x, t, a, b;
};

struct query{
	int x, y, i;
};

int n, k, q;
int ans[maxn];
vector<store> v;
vector<query> Q;
vector<int> cord;
unordered_map<int,int> ind;

int32_t main(){
	cin >> n >> k >> q; v.resize(n); Q.resize(q); int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> v[i].x >> v[i].t >> v[i].a >> v[i].b;
		cord.pb(v[i].a), cord.pb(v[i].b);
	}
	for(int i = 0; i < q; i++){
		cin >> Q[i].x >> Q[i].y; Q[i].i=i;
		cord.pb(Q[i].y);
	}
	sort(all(cord)); cord.erase(unique(all(cord)),cord.end());
	for(auto u : cord) ind[u]=cnt++;
	for(auto &u : v) u.a=ind[u.a], u.b=ind[u.b];
	for(auto &u : Q) u.y=ind[u.y];
	sort(all(v), [&](store a, store b){
		if(a.a!=b.a) return a.a < b.a;
		if(a.b!=b.b) return a.b < b.b;
		if(a.x!=b.x) return a.x < b.x;
		return a.t < b.t;
	});
	sort(all(Q), [&](query a, query b){
		if(a.y!=b.y) return a.y < b.y;
		if(a.x!=b.x) return a.x < b.x;
		return a.i < b.i;
	});
	int i = 0, j = 0;
	multiset<int> S[k+1];
	set<pair<int,int>> cur;
	for(int Time = 0; Time < cnt; Time++){
		while(i < sz(v) and v[i].a==Time){
			S[v[i].t].insert(v[i].x); 
			cur.insert({v[i].b,i}); i++;
		}
		while(j < sz(Q) and Q[j].y==Time){
			for(int l = 1; l <= k; l++){
				if(S[l].empty()){ans[Q[j].i]=-1; break;}
				auto itr = S[l].lower_bound(Q[j].x);
				auto itr2 = itr; if(itr2!=S[l].begin()) itr2--;
				int dis = LINF;
				if(itr!=S[l].end()) dis = min(dis, abs(*itr-Q[j].x));
				if(itr2!=S[l].end()) dis = min(dis, abs(*itr2-Q[j].x));
				ans[Q[j].i] = max(ans[Q[j].i], dis);
			}
			j++;
		}
		while(!cur.empty()){
			auto itr = cur.begin(); int i = itr->se;
			if(itr->fi==Time){
				S[v[i].t].erase(S[v[i].t].find(v[i].x));
				cur.erase(cur.begin());
			}
			else break;
		}
	}
	for(int i = 0; i < q; i++) cout << ans[i] << "\n";
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 456 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 444 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 316 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 456 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 444 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 316 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2392 ms 23780 KB Output is correct
32 Correct 122 ms 9224 KB Output is correct
33 Correct 295 ms 19532 KB Output is correct
34 Correct 1800 ms 19632 KB Output is correct
35 Correct 1134 ms 23868 KB Output is correct
36 Correct 387 ms 23608 KB Output is correct
37 Correct 289 ms 17652 KB Output is correct
38 Correct 227 ms 17560 KB Output is correct
39 Correct 210 ms 17244 KB Output is correct
40 Correct 221 ms 17308 KB Output is correct
41 Correct 454 ms 17376 KB Output is correct
42 Correct 359 ms 17540 KB Output is correct
43 Correct 773 ms 15084 KB Output is correct
44 Correct 401 ms 17396 KB Output is correct
45 Correct 239 ms 17396 KB Output is correct
46 Correct 196 ms 17460 KB Output is correct
47 Correct 198 ms 17124 KB Output is correct
48 Correct 183 ms 17036 KB Output is correct
49 Correct 201 ms 17212 KB Output is correct
50 Correct 369 ms 17384 KB Output is correct
51 Correct 187 ms 17084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5023 ms 73584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5025 ms 83816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 456 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 444 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 316 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2392 ms 23780 KB Output is correct
32 Correct 122 ms 9224 KB Output is correct
33 Correct 295 ms 19532 KB Output is correct
34 Correct 1800 ms 19632 KB Output is correct
35 Correct 1134 ms 23868 KB Output is correct
36 Correct 387 ms 23608 KB Output is correct
37 Correct 289 ms 17652 KB Output is correct
38 Correct 227 ms 17560 KB Output is correct
39 Correct 210 ms 17244 KB Output is correct
40 Correct 221 ms 17308 KB Output is correct
41 Correct 454 ms 17376 KB Output is correct
42 Correct 359 ms 17540 KB Output is correct
43 Correct 773 ms 15084 KB Output is correct
44 Correct 401 ms 17396 KB Output is correct
45 Correct 239 ms 17396 KB Output is correct
46 Correct 196 ms 17460 KB Output is correct
47 Correct 198 ms 17124 KB Output is correct
48 Correct 183 ms 17036 KB Output is correct
49 Correct 201 ms 17212 KB Output is correct
50 Correct 369 ms 17384 KB Output is correct
51 Correct 187 ms 17084 KB Output is correct
52 Correct 227 ms 26412 KB Output is correct
53 Correct 227 ms 22396 KB Output is correct
54 Correct 289 ms 24564 KB Output is correct
55 Execution timed out 5018 ms 20044 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 456 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 444 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 316 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2392 ms 23780 KB Output is correct
32 Correct 122 ms 9224 KB Output is correct
33 Correct 295 ms 19532 KB Output is correct
34 Correct 1800 ms 19632 KB Output is correct
35 Correct 1134 ms 23868 KB Output is correct
36 Correct 387 ms 23608 KB Output is correct
37 Correct 289 ms 17652 KB Output is correct
38 Correct 227 ms 17560 KB Output is correct
39 Correct 210 ms 17244 KB Output is correct
40 Correct 221 ms 17308 KB Output is correct
41 Correct 454 ms 17376 KB Output is correct
42 Correct 359 ms 17540 KB Output is correct
43 Correct 773 ms 15084 KB Output is correct
44 Correct 401 ms 17396 KB Output is correct
45 Correct 239 ms 17396 KB Output is correct
46 Correct 196 ms 17460 KB Output is correct
47 Correct 198 ms 17124 KB Output is correct
48 Correct 183 ms 17036 KB Output is correct
49 Correct 201 ms 17212 KB Output is correct
50 Correct 369 ms 17384 KB Output is correct
51 Correct 187 ms 17084 KB Output is correct
52 Execution timed out 5023 ms 73584 KB Time limit exceeded
53 Halted 0 ms 0 KB -