답안 #217270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217270 2020-03-29T10:38:53 Z theStaticMind 새 집 (APIO18_new_home) C++14
57 / 100
5000 ms 263548 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;
#define rand() (1ll * rand() * rand() + rand() + 1)

int S;

struct MaxSeg{
	vector<int> seg;

	void build(){
		S = (1 << (int)ceil(log2(sz(seg))));
		int l = S - sz(seg);
		for(int i = 0; i < l; i++) seg.pb(-INF);
		reverse(all(seg));
		for(int i = 1; i < sz(seg); i += 2) seg.pb(max(seg[i - 1], seg[i]));
		seg.pb(0);
		reverse(all(seg));
	}

	MaxSeg(int n){
		seg = vector<int>(n, -INF);
		build();
	}

	int query(int a, int b, int j = 1, int l = 0, int r = S - 1){
		if(r < a || b < l) return -INF;
		if(a <= l && r <= b) return seg[j];
		return max(query(a,b,j*2,l,(l+r)/2), query(a,b,j*2+1,(l+r)/2+1,r));
	}
	void update(int j, int v){
		j += S;
		seg[j] = v;
		j /= 2;
		while(j != 0){
			seg[j] = max(seg[j * 2], seg[j * 2 + 1]);
			j /= 2;
		}
	}
};

struct Store{
	int x, type, tl, tr, id;
};
struct Query{
	int x, time, id;
};
struct Event{
	int t, l, r, i, id; 
	Event(int a, int b, int c, int d, int e){
		t=a,l=b,r=c,i=d,id=e;
	}
	int mid(){
		return (l + r) / 2;
	}
	bool operator<=(Event& A){
		if(mid() < A.mid()) return true;
		if(mid() == A.mid()){
			if(id <= A.id) return true;
		}
		return false;
	}

} ;
vector<Event> E;

int ind = 0;

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

	vector<Store> X, Y;
	vector<Query> Q;
	vector<int> ans(q);
	vector<int> cnt(k + 1, 0);
	map<int, int> K[k + 1];
	int c = k;

	for(int i = 1; i <= k; i++) {
		K[i][2e9]++, K[i][-2e9]++;
		E.pb(Event(-1, -2e9, 2e9, 1, i));
	}

	for(int i = 0; i < n; i++){
		int a, b, c, d; 
		cin >> a >> b >> c >> d; a*=2;
		X.pb({a, b, c, d, i});
		Y.pb({a, b, c, d, i});
	}
	for(int i = 0; i < q; i++){
		int a, b; 
		cin >> a >> b; a*=2;
		Q.pb({a, b, i});
	}

	sort(all(X), [&](Store& A, Store& B){return A.tl < B.tl;});
	sort(all(Y), [&](Store& A, Store& B){return A.tr < B.tr;});
	sort(all(Q), [&](Query& A, Query& B){return A.time < B.time;});

	int a = 0, b = 0;

	for(auto& curr : Q){
		while(a < n && X[a].tl <= curr.time){
			int t = X[a].type, x = X[a].x;
			if(++cnt[t] == 1) c--;

			if(!K[t].count(x)){
				auto next = K[t].upper_bound(x);
				auto prev = std::prev(next);

				E.pb(Event(X[a].tl, prev->first, next->first, 0, t));
				E.pb(Event(X[a].tl, prev->first, x, 1, t));
				E.pb(Event(X[a].tl, x, next->first, 1, t));

			}
			K[t][x]++;

			a++;
		}
		while(b < n && Y[b].tr < curr.time){
			int t = Y[b].type, x = Y[b].x;
			if(--cnt[Y[b].type] == 0) c++;

			if(K[t][x] == 1){	
				K[t].erase(x);

				auto next = K[t].upper_bound(x);
				auto prev = std::prev(next);
				
				E.pb(Event(Y[b].tr+1, prev->first, x, 0, t));
				E.pb(Event(Y[b].tr+1, x, next->first, 0, t));
				E.pb(Event(Y[b].tr+1, prev->first, next->first, 1, t));
			}
			else{
				K[t][x]--;
			}

			b++;
		}
		if(c > 0){
			ans[curr.id] = -2;
			continue;
		}

	}

	MaxSeg L(sz(E)), R(sz(E));

	a = 0;

	vector<int> seq;
	for(int i = 0; i < sz(E); i++) seq.pb(i);
	sort(all(seq), [&](int x, int y){return E[x] <= E[y];});

	auto lower = [&](Event x){
		int l = 0, r = sz(seq) - 1;
		int ret = 0;
		while(l <= r){
			int mid = (l + r) / 2;
			if(x <= E[seq[mid]]){
				ret = mid;
				r = mid - 1;
			}
			else l = mid + 1;
		}
		return ret;
	};
	int w;
	for(auto& curr : Q){
		while(a < sz(E) && E[a].t <= curr.time){
			w = lower(E[a]);
			if(E[a].i){
				R.update(w, -E[a].l);
				L.update(w, E[a].r);
			}
			else{
				R.update(w, -INF);
				L.update(w, -INF);
			}
			a++;
		}
		if(ans[curr.id] == -2){
			continue;
		}
		int x = curr.x;
		w = lower(Event(0,x,x,1,-1));
		ans[curr.id] = max(L.query(0, w - 1) - x, R.query(w, S-1) + x);

	}

	for(int i = 0; i < q; i++) cout << ans[i] / 2 << ' ';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 512 KB Output is correct
6 Correct 6 ms 748 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 756 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 6 ms 764 KB Output is correct
11 Correct 6 ms 748 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 756 KB Output is correct
16 Correct 6 ms 756 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 756 KB Output is correct
19 Correct 6 ms 756 KB Output is correct
20 Correct 6 ms 756 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 6 ms 896 KB Output is correct
23 Correct 6 ms 756 KB Output is correct
24 Correct 6 ms 756 KB Output is correct
25 Correct 6 ms 748 KB Output is correct
26 Correct 6 ms 748 KB Output is correct
27 Correct 6 ms 748 KB Output is correct
28 Correct 6 ms 744 KB Output is correct
29 Correct 6 ms 748 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 512 KB Output is correct
6 Correct 6 ms 748 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 756 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 6 ms 764 KB Output is correct
11 Correct 6 ms 748 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 756 KB Output is correct
16 Correct 6 ms 756 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 756 KB Output is correct
19 Correct 6 ms 756 KB Output is correct
20 Correct 6 ms 756 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 6 ms 896 KB Output is correct
23 Correct 6 ms 756 KB Output is correct
24 Correct 6 ms 756 KB Output is correct
25 Correct 6 ms 748 KB Output is correct
26 Correct 6 ms 748 KB Output is correct
27 Correct 6 ms 748 KB Output is correct
28 Correct 6 ms 744 KB Output is correct
29 Correct 6 ms 748 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
31 Correct 758 ms 51164 KB Output is correct
32 Correct 59 ms 9528 KB Output is correct
33 Correct 688 ms 50320 KB Output is correct
34 Correct 740 ms 50956 KB Output is correct
35 Correct 782 ms 49328 KB Output is correct
36 Correct 708 ms 51852 KB Output is correct
37 Correct 458 ms 49424 KB Output is correct
38 Correct 424 ms 49420 KB Output is correct
39 Correct 354 ms 49204 KB Output is correct
40 Correct 339 ms 49220 KB Output is correct
41 Correct 761 ms 49464 KB Output is correct
42 Correct 685 ms 49348 KB Output is correct
43 Correct 75 ms 11448 KB Output is correct
44 Correct 713 ms 49588 KB Output is correct
45 Correct 696 ms 49424 KB Output is correct
46 Correct 715 ms 49292 KB Output is correct
47 Correct 374 ms 48012 KB Output is correct
48 Correct 337 ms 47500 KB Output is correct
49 Correct 299 ms 48400 KB Output is correct
50 Correct 351 ms 48936 KB Output is correct
51 Correct 319 ms 48272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2874 ms 172208 KB Output is correct
2 Correct 2481 ms 155260 KB Output is correct
3 Correct 2626 ms 263536 KB Output is correct
4 Correct 2914 ms 182184 KB Output is correct
5 Correct 2294 ms 154744 KB Output is correct
6 Correct 2371 ms 155316 KB Output is correct
7 Correct 1796 ms 263548 KB Output is correct
8 Correct 2425 ms 182112 KB Output is correct
9 Correct 2453 ms 165024 KB Output is correct
10 Correct 2492 ms 156600 KB Output is correct
11 Correct 1073 ms 153268 KB Output is correct
12 Correct 1171 ms 155700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5078 ms 241056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 512 KB Output is correct
6 Correct 6 ms 748 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 756 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 6 ms 764 KB Output is correct
11 Correct 6 ms 748 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 756 KB Output is correct
16 Correct 6 ms 756 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 756 KB Output is correct
19 Correct 6 ms 756 KB Output is correct
20 Correct 6 ms 756 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 6 ms 896 KB Output is correct
23 Correct 6 ms 756 KB Output is correct
24 Correct 6 ms 756 KB Output is correct
25 Correct 6 ms 748 KB Output is correct
26 Correct 6 ms 748 KB Output is correct
27 Correct 6 ms 748 KB Output is correct
28 Correct 6 ms 744 KB Output is correct
29 Correct 6 ms 748 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
31 Correct 758 ms 51164 KB Output is correct
32 Correct 59 ms 9528 KB Output is correct
33 Correct 688 ms 50320 KB Output is correct
34 Correct 740 ms 50956 KB Output is correct
35 Correct 782 ms 49328 KB Output is correct
36 Correct 708 ms 51852 KB Output is correct
37 Correct 458 ms 49424 KB Output is correct
38 Correct 424 ms 49420 KB Output is correct
39 Correct 354 ms 49204 KB Output is correct
40 Correct 339 ms 49220 KB Output is correct
41 Correct 761 ms 49464 KB Output is correct
42 Correct 685 ms 49348 KB Output is correct
43 Correct 75 ms 11448 KB Output is correct
44 Correct 713 ms 49588 KB Output is correct
45 Correct 696 ms 49424 KB Output is correct
46 Correct 715 ms 49292 KB Output is correct
47 Correct 374 ms 48012 KB Output is correct
48 Correct 337 ms 47500 KB Output is correct
49 Correct 299 ms 48400 KB Output is correct
50 Correct 351 ms 48936 KB Output is correct
51 Correct 319 ms 48272 KB Output is correct
52 Correct 738 ms 64100 KB Output is correct
53 Correct 721 ms 65248 KB Output is correct
54 Correct 682 ms 54056 KB Output is correct
55 Correct 693 ms 54544 KB Output is correct
56 Correct 687 ms 58664 KB Output is correct
57 Correct 706 ms 51776 KB Output is correct
58 Correct 699 ms 55332 KB Output is correct
59 Correct 691 ms 58532 KB Output is correct
60 Correct 682 ms 50876 KB Output is correct
61 Correct 186 ms 48120 KB Output is correct
62 Correct 759 ms 65664 KB Output is correct
63 Correct 702 ms 58316 KB Output is correct
64 Correct 710 ms 54184 KB Output is correct
65 Correct 720 ms 51184 KB Output is correct
66 Correct 722 ms 49660 KB Output is correct
67 Correct 619 ms 49092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 512 KB Output is correct
6 Correct 6 ms 748 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 756 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 6 ms 764 KB Output is correct
11 Correct 6 ms 748 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 756 KB Output is correct
16 Correct 6 ms 756 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 756 KB Output is correct
19 Correct 6 ms 756 KB Output is correct
20 Correct 6 ms 756 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 6 ms 896 KB Output is correct
23 Correct 6 ms 756 KB Output is correct
24 Correct 6 ms 756 KB Output is correct
25 Correct 6 ms 748 KB Output is correct
26 Correct 6 ms 748 KB Output is correct
27 Correct 6 ms 748 KB Output is correct
28 Correct 6 ms 744 KB Output is correct
29 Correct 6 ms 748 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
31 Correct 758 ms 51164 KB Output is correct
32 Correct 59 ms 9528 KB Output is correct
33 Correct 688 ms 50320 KB Output is correct
34 Correct 740 ms 50956 KB Output is correct
35 Correct 782 ms 49328 KB Output is correct
36 Correct 708 ms 51852 KB Output is correct
37 Correct 458 ms 49424 KB Output is correct
38 Correct 424 ms 49420 KB Output is correct
39 Correct 354 ms 49204 KB Output is correct
40 Correct 339 ms 49220 KB Output is correct
41 Correct 761 ms 49464 KB Output is correct
42 Correct 685 ms 49348 KB Output is correct
43 Correct 75 ms 11448 KB Output is correct
44 Correct 713 ms 49588 KB Output is correct
45 Correct 696 ms 49424 KB Output is correct
46 Correct 715 ms 49292 KB Output is correct
47 Correct 374 ms 48012 KB Output is correct
48 Correct 337 ms 47500 KB Output is correct
49 Correct 299 ms 48400 KB Output is correct
50 Correct 351 ms 48936 KB Output is correct
51 Correct 319 ms 48272 KB Output is correct
52 Correct 2874 ms 172208 KB Output is correct
53 Correct 2481 ms 155260 KB Output is correct
54 Correct 2626 ms 263536 KB Output is correct
55 Correct 2914 ms 182184 KB Output is correct
56 Correct 2294 ms 154744 KB Output is correct
57 Correct 2371 ms 155316 KB Output is correct
58 Correct 1796 ms 263548 KB Output is correct
59 Correct 2425 ms 182112 KB Output is correct
60 Correct 2453 ms 165024 KB Output is correct
61 Correct 2492 ms 156600 KB Output is correct
62 Correct 1073 ms 153268 KB Output is correct
63 Correct 1171 ms 155700 KB Output is correct
64 Execution timed out 5078 ms 241056 KB Time limit exceeded
65 Halted 0 ms 0 KB -