답안 #401873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401873 2021-05-10T22:53:43 Z faresbasbs 새 집 (APIO18_new_home) C++14
47 / 100
5000 ms 232884 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

struct query{
	int x,t,type;
	bool operator <(query b) const{
		if(t == b.t){
			return type < b.type;
		}
		return t < b.t;
	}
};

vector<ordered_set> segment;
int n,N,q,k,t,ans[300001];
multiset<int> ms[300001];
vector<query> qs;
vector<int> all;

void del(int curr , int val){
	for( ; curr <= N ; curr += curr&(-curr)){
		segment[curr].erase(segment[curr].find_by_order(segment[curr].order_of_key(val)));
	}
}

void add(int curr , int val){
	for( ; curr <= N ; curr += curr&(-curr)){
		segment[curr].insert(val);
	}
}

int cmp(int val){
	return lower_bound(all.begin(),all.end(),val)-all.begin()+1;
}

int num(int curr , int val){
	int ret = 0;
	for( ; curr ; curr -= curr&(-curr)){
		ret += segment[curr].size()-segment[curr].order_of_key(val);
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	cin >> n >> k >> q;
	for(int i = 1 ; i <= k ; i += 1){
		ms[i].insert(100000001);
	}
	for(int i = 0 ; i < n ; i += 1){
		int x,t,a,b;
		cin >> x >> t >> a >> b;
		all.push_back(x);
		qs.push_back({x,a,t});
		qs.push_back({x,b+1,-t});
	}
	for(int i = 1 ; i <= q ; i += 1){
		int l,y;
		cin >> l >> y;
		all.push_back(l);
		qs.push_back({l,y,k+i});
	}
	sort(all.begin(),all.end());
	all.erase(unique(all.begin(),all.end()),all.end());
	segment.resize(all.size()+1);
	sort(qs.begin(),qs.end());
	N = all.size();
	for(auto i : qs){
		if(i.type > k){
			i.type -= k;
			if(num(N,N+1) < k){
				ans[i.type] = -1;
				continue;
			}
			int first = -1 , last = 100000000;
			while(last-first > 1){
				int mid = (first+last)/2 , val1 = lower_bound(all.begin(),all.end(),i.x-mid)-all.begin()+1;
				int val2 = upper_bound(all.begin(),all.end(),i.x+mid)-all.begin();
				if(num(val2,val2+1)-num(val1-1,val2+1) >= k){
					last = mid;
				}else{
					first = mid;
				}
			}
			ans[i.type] = last;
		}else if(i.type > 0){
			i.x = cmp(i.x);
			auto it = ms[i.type].lower_bound(i.x);
			int val = *it;
			add(i.x,val);
			if(it != ms[i.type].begin()){
				it--;
				int pos = *it;
				del(pos,val) , add(pos,i.x);
			}
			ms[i.type].insert(i.x);
		}else{
			i.x = cmp(i.x);
			i.type = -i.type;
			ms[i.type].erase(ms[i.type].find(i.x));
			auto it = ms[i.type].lower_bound(i.x);
			int val = *it;
			del(i.x,val);
			if(it != ms[i.type].begin()){
				it--;
				int pos = *it;
				del(pos,i.x) , add(pos,val);
			}
		}
	}
	for(int i = 1 ; i <= q ; i += 1){
		cout << ans[i] << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14372 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 9 ms 14336 KB Output is correct
5 Correct 11 ms 14412 KB Output is correct
6 Correct 13 ms 14540 KB Output is correct
7 Correct 10 ms 14540 KB Output is correct
8 Correct 11 ms 14540 KB Output is correct
9 Correct 10 ms 14644 KB Output is correct
10 Correct 14 ms 14540 KB Output is correct
11 Correct 11 ms 14436 KB Output is correct
12 Correct 13 ms 14404 KB Output is correct
13 Correct 10 ms 14388 KB Output is correct
14 Correct 11 ms 14412 KB Output is correct
15 Correct 12 ms 14564 KB Output is correct
16 Correct 12 ms 14496 KB Output is correct
17 Correct 12 ms 14540 KB Output is correct
18 Correct 11 ms 14572 KB Output is correct
19 Correct 11 ms 14540 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14492 KB Output is correct
22 Correct 11 ms 14540 KB Output is correct
23 Correct 11 ms 14540 KB Output is correct
24 Correct 12 ms 14576 KB Output is correct
25 Correct 12 ms 14532 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14364 KB Output is correct
28 Correct 11 ms 14520 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14372 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 9 ms 14336 KB Output is correct
5 Correct 11 ms 14412 KB Output is correct
6 Correct 13 ms 14540 KB Output is correct
7 Correct 10 ms 14540 KB Output is correct
8 Correct 11 ms 14540 KB Output is correct
9 Correct 10 ms 14644 KB Output is correct
10 Correct 14 ms 14540 KB Output is correct
11 Correct 11 ms 14436 KB Output is correct
12 Correct 13 ms 14404 KB Output is correct
13 Correct 10 ms 14388 KB Output is correct
14 Correct 11 ms 14412 KB Output is correct
15 Correct 12 ms 14564 KB Output is correct
16 Correct 12 ms 14496 KB Output is correct
17 Correct 12 ms 14540 KB Output is correct
18 Correct 11 ms 14572 KB Output is correct
19 Correct 11 ms 14540 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14492 KB Output is correct
22 Correct 11 ms 14540 KB Output is correct
23 Correct 11 ms 14540 KB Output is correct
24 Correct 12 ms 14576 KB Output is correct
25 Correct 12 ms 14532 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14364 KB Output is correct
28 Correct 11 ms 14520 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14412 KB Output is correct
31 Correct 4984 ms 54160 KB Output is correct
32 Correct 1116 ms 21868 KB Output is correct
33 Correct 3750 ms 39888 KB Output is correct
34 Correct 3868 ms 40208 KB Output is correct
35 Correct 4927 ms 57184 KB Output is correct
36 Correct 4657 ms 56964 KB Output is correct
37 Correct 2162 ms 32168 KB Output is correct
38 Correct 2157 ms 32284 KB Output is correct
39 Correct 1287 ms 30204 KB Output is correct
40 Correct 1415 ms 30408 KB Output is correct
41 Correct 985 ms 30268 KB Output is correct
42 Correct 739 ms 30188 KB Output is correct
43 Correct 152 ms 25720 KB Output is correct
44 Correct 933 ms 30336 KB Output is correct
45 Correct 828 ms 30148 KB Output is correct
46 Correct 803 ms 30064 KB Output is correct
47 Correct 522 ms 29360 KB Output is correct
48 Correct 589 ms 29256 KB Output is correct
49 Correct 681 ms 29544 KB Output is correct
50 Correct 737 ms 29932 KB Output is correct
51 Correct 716 ms 29508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5097 ms 232884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5051 ms 225400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14372 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 9 ms 14336 KB Output is correct
5 Correct 11 ms 14412 KB Output is correct
6 Correct 13 ms 14540 KB Output is correct
7 Correct 10 ms 14540 KB Output is correct
8 Correct 11 ms 14540 KB Output is correct
9 Correct 10 ms 14644 KB Output is correct
10 Correct 14 ms 14540 KB Output is correct
11 Correct 11 ms 14436 KB Output is correct
12 Correct 13 ms 14404 KB Output is correct
13 Correct 10 ms 14388 KB Output is correct
14 Correct 11 ms 14412 KB Output is correct
15 Correct 12 ms 14564 KB Output is correct
16 Correct 12 ms 14496 KB Output is correct
17 Correct 12 ms 14540 KB Output is correct
18 Correct 11 ms 14572 KB Output is correct
19 Correct 11 ms 14540 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14492 KB Output is correct
22 Correct 11 ms 14540 KB Output is correct
23 Correct 11 ms 14540 KB Output is correct
24 Correct 12 ms 14576 KB Output is correct
25 Correct 12 ms 14532 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14364 KB Output is correct
28 Correct 11 ms 14520 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14412 KB Output is correct
31 Correct 4984 ms 54160 KB Output is correct
32 Correct 1116 ms 21868 KB Output is correct
33 Correct 3750 ms 39888 KB Output is correct
34 Correct 3868 ms 40208 KB Output is correct
35 Correct 4927 ms 57184 KB Output is correct
36 Correct 4657 ms 56964 KB Output is correct
37 Correct 2162 ms 32168 KB Output is correct
38 Correct 2157 ms 32284 KB Output is correct
39 Correct 1287 ms 30204 KB Output is correct
40 Correct 1415 ms 30408 KB Output is correct
41 Correct 985 ms 30268 KB Output is correct
42 Correct 739 ms 30188 KB Output is correct
43 Correct 152 ms 25720 KB Output is correct
44 Correct 933 ms 30336 KB Output is correct
45 Correct 828 ms 30148 KB Output is correct
46 Correct 803 ms 30064 KB Output is correct
47 Correct 522 ms 29360 KB Output is correct
48 Correct 589 ms 29256 KB Output is correct
49 Correct 681 ms 29544 KB Output is correct
50 Correct 737 ms 29932 KB Output is correct
51 Correct 716 ms 29508 KB Output is correct
52 Correct 709 ms 59852 KB Output is correct
53 Correct 621 ms 42644 KB Output is correct
54 Correct 1477 ms 57964 KB Output is correct
55 Correct 1441 ms 40432 KB Output is correct
56 Correct 1447 ms 45232 KB Output is correct
57 Correct 1290 ms 33260 KB Output is correct
58 Correct 1209 ms 40476 KB Output is correct
59 Correct 1100 ms 45224 KB Output is correct
60 Correct 1066 ms 33456 KB Output is correct
61 Correct 160 ms 28656 KB Output is correct
62 Correct 924 ms 59888 KB Output is correct
63 Correct 1701 ms 54064 KB Output is correct
64 Correct 1999 ms 49136 KB Output is correct
65 Correct 1794 ms 36636 KB Output is correct
66 Correct 1120 ms 30800 KB Output is correct
67 Correct 661 ms 21612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14372 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 9 ms 14336 KB Output is correct
5 Correct 11 ms 14412 KB Output is correct
6 Correct 13 ms 14540 KB Output is correct
7 Correct 10 ms 14540 KB Output is correct
8 Correct 11 ms 14540 KB Output is correct
9 Correct 10 ms 14644 KB Output is correct
10 Correct 14 ms 14540 KB Output is correct
11 Correct 11 ms 14436 KB Output is correct
12 Correct 13 ms 14404 KB Output is correct
13 Correct 10 ms 14388 KB Output is correct
14 Correct 11 ms 14412 KB Output is correct
15 Correct 12 ms 14564 KB Output is correct
16 Correct 12 ms 14496 KB Output is correct
17 Correct 12 ms 14540 KB Output is correct
18 Correct 11 ms 14572 KB Output is correct
19 Correct 11 ms 14540 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14492 KB Output is correct
22 Correct 11 ms 14540 KB Output is correct
23 Correct 11 ms 14540 KB Output is correct
24 Correct 12 ms 14576 KB Output is correct
25 Correct 12 ms 14532 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14364 KB Output is correct
28 Correct 11 ms 14520 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14412 KB Output is correct
31 Correct 4984 ms 54160 KB Output is correct
32 Correct 1116 ms 21868 KB Output is correct
33 Correct 3750 ms 39888 KB Output is correct
34 Correct 3868 ms 40208 KB Output is correct
35 Correct 4927 ms 57184 KB Output is correct
36 Correct 4657 ms 56964 KB Output is correct
37 Correct 2162 ms 32168 KB Output is correct
38 Correct 2157 ms 32284 KB Output is correct
39 Correct 1287 ms 30204 KB Output is correct
40 Correct 1415 ms 30408 KB Output is correct
41 Correct 985 ms 30268 KB Output is correct
42 Correct 739 ms 30188 KB Output is correct
43 Correct 152 ms 25720 KB Output is correct
44 Correct 933 ms 30336 KB Output is correct
45 Correct 828 ms 30148 KB Output is correct
46 Correct 803 ms 30064 KB Output is correct
47 Correct 522 ms 29360 KB Output is correct
48 Correct 589 ms 29256 KB Output is correct
49 Correct 681 ms 29544 KB Output is correct
50 Correct 737 ms 29932 KB Output is correct
51 Correct 716 ms 29508 KB Output is correct
52 Execution timed out 5097 ms 232884 KB Time limit exceeded
53 Halted 0 ms 0 KB -