답안 #203838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203838 2020-02-22T13:49:20 Z Segtree 새 집 (APIO18_new_home) C++14
100 / 100
4485 ms 141968 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define N 600010
ll dat[2*N];
void init(){
	rep(i,2*N)dat[i]=-1e17;
}
void upd(ll i,ll x){
	i+=N,dat[i]=x;
	for(;i;i>>=1)dat[i/2]=max(dat[i],dat[i^1]);
}
ll qry(ll l,ll r){
	l+=N,r+=N;
	ll res=-1e17;
	for(ll a=l,b=r;a<b;a>>=1,b>>=1){
		if(a&1)chmax(res,dat[a++]);
		if(b&1)chmax(res,dat[--b]);
	}
	return res;
}

struct st{
	ll tim,typ,c,d;
	bool operator<(const st&key)const{
		if(this->tim==key.tim){
			return this->typ<key.typ;
		}
		return this->tim<key.tim;
	}
};
ll n,q,k,x[N],t[N],a[N],b[N],fans[N];
multiset<ll> s[N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>k>>q;
	vector<pair<ll,ll> > xs;
	rep(i,n){
		cin>>x[i]>>t[i]>>a[i]>>b[i];
		t[i]--;
		xs.push_back(make_pair(x[i],i));
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	vector<st> v;
	rep(i,n){
		pair<ll,ll> key=make_pair(x[i],i);
		x[i]=lower_bound(xs.begin(),xs.end(),key)-xs.begin();
		v.push_back((struct st){a[i],0,x[i]+k,t[i]});
		v.push_back((struct st){b[i],2,x[i]+k,t[i]});
	}
	rep(i,q){
		ll l,y; cin>>l>>y;
		v.push_back((struct st){y,1,l,i});
	}
	sort(v.begin(),v.end());
	init();
	rep(i,k){
		s[i].insert(i);
		s[i].insert(1e17);
		upd(i,1e17);
	}
	for(auto e:v){
		if(e.typ==0){
			ll place=e.c,col=e.d;
			auto it=s[col].upper_bound(place);
			ll r=*it;
			it--;
			ll l=*it;
			upd(l,place);
			upd(place,r);
			s[col].insert(place);
		}
		if(e.typ==1){
			ll place=e.c,id=e.d;
			ll L=-1,R=1e9,mid;
			while(L<R-1){
				mid=(L+R)>>1;
				pair<ll,ll> key;
				key=make_pair(place-mid,-1e17);
				ll l=lower_bound(xs.begin(),xs.end(),key)-xs.begin()+k;
				key=make_pair(place+mid,+1e17);
				ll r=upper_bound(xs.begin(),xs.end(),key)-xs.begin()-1+k;
				if(qry(0,l)<=r)R=mid;
				else L=mid;
			}
			if(R==1e9)R=-1;
			fans[id]=R;
		}
		if(e.typ==2){
			ll place=e.c,col=e.d;
			s[col].erase(s[col].find(place));
			auto it=s[col].upper_bound(place);
			ll r=*it;
			it--;
			ll l=*it;
			upd(place,-1e17);
			upd(l,r);
		}
	}
	rep(i,q)cout<<fans[i]<<"\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 37880 KB Output is correct
2 Correct 28 ms 37880 KB Output is correct
3 Correct 28 ms 37880 KB Output is correct
4 Correct 28 ms 38008 KB Output is correct
5 Correct 30 ms 38136 KB Output is correct
6 Correct 30 ms 38136 KB Output is correct
7 Correct 30 ms 38012 KB Output is correct
8 Correct 30 ms 38136 KB Output is correct
9 Correct 30 ms 38136 KB Output is correct
10 Correct 30 ms 38008 KB Output is correct
11 Correct 30 ms 38132 KB Output is correct
12 Correct 29 ms 38136 KB Output is correct
13 Correct 29 ms 38136 KB Output is correct
14 Correct 29 ms 38132 KB Output is correct
15 Correct 30 ms 38136 KB Output is correct
16 Correct 30 ms 38112 KB Output is correct
17 Correct 29 ms 38136 KB Output is correct
18 Correct 31 ms 38136 KB Output is correct
19 Correct 30 ms 38140 KB Output is correct
20 Correct 30 ms 38136 KB Output is correct
21 Correct 29 ms 38136 KB Output is correct
22 Correct 30 ms 38136 KB Output is correct
23 Correct 32 ms 38136 KB Output is correct
24 Correct 31 ms 38136 KB Output is correct
25 Correct 30 ms 38136 KB Output is correct
26 Correct 31 ms 38136 KB Output is correct
27 Correct 30 ms 38008 KB Output is correct
28 Correct 30 ms 38136 KB Output is correct
29 Correct 29 ms 38136 KB Output is correct
30 Correct 31 ms 38136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 37880 KB Output is correct
2 Correct 28 ms 37880 KB Output is correct
3 Correct 28 ms 37880 KB Output is correct
4 Correct 28 ms 38008 KB Output is correct
5 Correct 30 ms 38136 KB Output is correct
6 Correct 30 ms 38136 KB Output is correct
7 Correct 30 ms 38012 KB Output is correct
8 Correct 30 ms 38136 KB Output is correct
9 Correct 30 ms 38136 KB Output is correct
10 Correct 30 ms 38008 KB Output is correct
11 Correct 30 ms 38132 KB Output is correct
12 Correct 29 ms 38136 KB Output is correct
13 Correct 29 ms 38136 KB Output is correct
14 Correct 29 ms 38132 KB Output is correct
15 Correct 30 ms 38136 KB Output is correct
16 Correct 30 ms 38112 KB Output is correct
17 Correct 29 ms 38136 KB Output is correct
18 Correct 31 ms 38136 KB Output is correct
19 Correct 30 ms 38140 KB Output is correct
20 Correct 30 ms 38136 KB Output is correct
21 Correct 29 ms 38136 KB Output is correct
22 Correct 30 ms 38136 KB Output is correct
23 Correct 32 ms 38136 KB Output is correct
24 Correct 31 ms 38136 KB Output is correct
25 Correct 30 ms 38136 KB Output is correct
26 Correct 31 ms 38136 KB Output is correct
27 Correct 30 ms 38008 KB Output is correct
28 Correct 30 ms 38136 KB Output is correct
29 Correct 29 ms 38136 KB Output is correct
30 Correct 31 ms 38136 KB Output is correct
31 Correct 548 ms 53208 KB Output is correct
32 Correct 241 ms 49108 KB Output is correct
33 Correct 571 ms 51280 KB Output is correct
34 Correct 510 ms 51540 KB Output is correct
35 Correct 599 ms 53084 KB Output is correct
36 Correct 604 ms 53084 KB Output is correct
37 Correct 518 ms 50384 KB Output is correct
38 Correct 526 ms 50396 KB Output is correct
39 Correct 471 ms 50392 KB Output is correct
40 Correct 479 ms 50256 KB Output is correct
41 Correct 338 ms 50644 KB Output is correct
42 Correct 291 ms 50388 KB Output is correct
43 Correct 235 ms 52700 KB Output is correct
44 Correct 336 ms 50648 KB Output is correct
45 Correct 368 ms 50488 KB Output is correct
46 Correct 421 ms 50384 KB Output is correct
47 Correct 321 ms 49752 KB Output is correct
48 Correct 359 ms 49756 KB Output is correct
49 Correct 373 ms 50004 KB Output is correct
50 Correct 332 ms 50140 KB Output is correct
51 Correct 404 ms 50004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2148 ms 105232 KB Output is correct
2 Correct 3914 ms 110864 KB Output is correct
3 Correct 2103 ms 141668 KB Output is correct
4 Correct 2146 ms 122644 KB Output is correct
5 Correct 3930 ms 110268 KB Output is correct
6 Correct 3849 ms 110820 KB Output is correct
7 Correct 1876 ms 141608 KB Output is correct
8 Correct 1941 ms 122628 KB Output is correct
9 Correct 2357 ms 115992 KB Output is correct
10 Correct 3455 ms 112144 KB Output is correct
11 Correct 2598 ms 110224 KB Output is correct
12 Correct 2667 ms 111756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3153 ms 99700 KB Output is correct
2 Correct 1302 ms 101584 KB Output is correct
3 Correct 4198 ms 110588 KB Output is correct
4 Correct 1763 ms 139404 KB Output is correct
5 Correct 1714 ms 116752 KB Output is correct
6 Correct 1754 ms 120724 KB Output is correct
7 Correct 4232 ms 110228 KB Output is correct
8 Correct 4269 ms 110476 KB Output is correct
9 Correct 1877 ms 140668 KB Output is correct
10 Correct 1995 ms 119524 KB Output is correct
11 Correct 2561 ms 113952 KB Output is correct
12 Correct 3878 ms 111632 KB Output is correct
13 Correct 2390 ms 108796 KB Output is correct
14 Correct 2354 ms 107920 KB Output is correct
15 Correct 2635 ms 109700 KB Output is correct
16 Correct 2790 ms 111268 KB Output is correct
17 Correct 2842 ms 109212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 37880 KB Output is correct
2 Correct 28 ms 37880 KB Output is correct
3 Correct 28 ms 37880 KB Output is correct
4 Correct 28 ms 38008 KB Output is correct
5 Correct 30 ms 38136 KB Output is correct
6 Correct 30 ms 38136 KB Output is correct
7 Correct 30 ms 38012 KB Output is correct
8 Correct 30 ms 38136 KB Output is correct
9 Correct 30 ms 38136 KB Output is correct
10 Correct 30 ms 38008 KB Output is correct
11 Correct 30 ms 38132 KB Output is correct
12 Correct 29 ms 38136 KB Output is correct
13 Correct 29 ms 38136 KB Output is correct
14 Correct 29 ms 38132 KB Output is correct
15 Correct 30 ms 38136 KB Output is correct
16 Correct 30 ms 38112 KB Output is correct
17 Correct 29 ms 38136 KB Output is correct
18 Correct 31 ms 38136 KB Output is correct
19 Correct 30 ms 38140 KB Output is correct
20 Correct 30 ms 38136 KB Output is correct
21 Correct 29 ms 38136 KB Output is correct
22 Correct 30 ms 38136 KB Output is correct
23 Correct 32 ms 38136 KB Output is correct
24 Correct 31 ms 38136 KB Output is correct
25 Correct 30 ms 38136 KB Output is correct
26 Correct 31 ms 38136 KB Output is correct
27 Correct 30 ms 38008 KB Output is correct
28 Correct 30 ms 38136 KB Output is correct
29 Correct 29 ms 38136 KB Output is correct
30 Correct 31 ms 38136 KB Output is correct
31 Correct 548 ms 53208 KB Output is correct
32 Correct 241 ms 49108 KB Output is correct
33 Correct 571 ms 51280 KB Output is correct
34 Correct 510 ms 51540 KB Output is correct
35 Correct 599 ms 53084 KB Output is correct
36 Correct 604 ms 53084 KB Output is correct
37 Correct 518 ms 50384 KB Output is correct
38 Correct 526 ms 50396 KB Output is correct
39 Correct 471 ms 50392 KB Output is correct
40 Correct 479 ms 50256 KB Output is correct
41 Correct 338 ms 50644 KB Output is correct
42 Correct 291 ms 50388 KB Output is correct
43 Correct 235 ms 52700 KB Output is correct
44 Correct 336 ms 50648 KB Output is correct
45 Correct 368 ms 50488 KB Output is correct
46 Correct 421 ms 50384 KB Output is correct
47 Correct 321 ms 49752 KB Output is correct
48 Correct 359 ms 49756 KB Output is correct
49 Correct 373 ms 50004 KB Output is correct
50 Correct 332 ms 50140 KB Output is correct
51 Correct 404 ms 50004 KB Output is correct
52 Correct 318 ms 58604 KB Output is correct
53 Correct 307 ms 56796 KB Output is correct
54 Correct 306 ms 54872 KB Output is correct
55 Correct 358 ms 53336 KB Output is correct
56 Correct 377 ms 54748 KB Output is correct
57 Correct 361 ms 51284 KB Output is correct
58 Correct 346 ms 53196 KB Output is correct
59 Correct 337 ms 54620 KB Output is correct
60 Correct 313 ms 51288 KB Output is correct
61 Correct 253 ms 58332 KB Output is correct
62 Correct 328 ms 58716 KB Output is correct
63 Correct 322 ms 55388 KB Output is correct
64 Correct 332 ms 54236 KB Output is correct
65 Correct 309 ms 51672 KB Output is correct
66 Correct 341 ms 50652 KB Output is correct
67 Correct 238 ms 49500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 37880 KB Output is correct
2 Correct 28 ms 37880 KB Output is correct
3 Correct 28 ms 37880 KB Output is correct
4 Correct 28 ms 38008 KB Output is correct
5 Correct 30 ms 38136 KB Output is correct
6 Correct 30 ms 38136 KB Output is correct
7 Correct 30 ms 38012 KB Output is correct
8 Correct 30 ms 38136 KB Output is correct
9 Correct 30 ms 38136 KB Output is correct
10 Correct 30 ms 38008 KB Output is correct
11 Correct 30 ms 38132 KB Output is correct
12 Correct 29 ms 38136 KB Output is correct
13 Correct 29 ms 38136 KB Output is correct
14 Correct 29 ms 38132 KB Output is correct
15 Correct 30 ms 38136 KB Output is correct
16 Correct 30 ms 38112 KB Output is correct
17 Correct 29 ms 38136 KB Output is correct
18 Correct 31 ms 38136 KB Output is correct
19 Correct 30 ms 38140 KB Output is correct
20 Correct 30 ms 38136 KB Output is correct
21 Correct 29 ms 38136 KB Output is correct
22 Correct 30 ms 38136 KB Output is correct
23 Correct 32 ms 38136 KB Output is correct
24 Correct 31 ms 38136 KB Output is correct
25 Correct 30 ms 38136 KB Output is correct
26 Correct 31 ms 38136 KB Output is correct
27 Correct 30 ms 38008 KB Output is correct
28 Correct 30 ms 38136 KB Output is correct
29 Correct 29 ms 38136 KB Output is correct
30 Correct 31 ms 38136 KB Output is correct
31 Correct 548 ms 53208 KB Output is correct
32 Correct 241 ms 49108 KB Output is correct
33 Correct 571 ms 51280 KB Output is correct
34 Correct 510 ms 51540 KB Output is correct
35 Correct 599 ms 53084 KB Output is correct
36 Correct 604 ms 53084 KB Output is correct
37 Correct 518 ms 50384 KB Output is correct
38 Correct 526 ms 50396 KB Output is correct
39 Correct 471 ms 50392 KB Output is correct
40 Correct 479 ms 50256 KB Output is correct
41 Correct 338 ms 50644 KB Output is correct
42 Correct 291 ms 50388 KB Output is correct
43 Correct 235 ms 52700 KB Output is correct
44 Correct 336 ms 50648 KB Output is correct
45 Correct 368 ms 50488 KB Output is correct
46 Correct 421 ms 50384 KB Output is correct
47 Correct 321 ms 49752 KB Output is correct
48 Correct 359 ms 49756 KB Output is correct
49 Correct 373 ms 50004 KB Output is correct
50 Correct 332 ms 50140 KB Output is correct
51 Correct 404 ms 50004 KB Output is correct
52 Correct 2148 ms 105232 KB Output is correct
53 Correct 3914 ms 110864 KB Output is correct
54 Correct 2103 ms 141668 KB Output is correct
55 Correct 2146 ms 122644 KB Output is correct
56 Correct 3930 ms 110268 KB Output is correct
57 Correct 3849 ms 110820 KB Output is correct
58 Correct 1876 ms 141608 KB Output is correct
59 Correct 1941 ms 122628 KB Output is correct
60 Correct 2357 ms 115992 KB Output is correct
61 Correct 3455 ms 112144 KB Output is correct
62 Correct 2598 ms 110224 KB Output is correct
63 Correct 2667 ms 111756 KB Output is correct
64 Correct 3153 ms 99700 KB Output is correct
65 Correct 1302 ms 101584 KB Output is correct
66 Correct 4198 ms 110588 KB Output is correct
67 Correct 1763 ms 139404 KB Output is correct
68 Correct 1714 ms 116752 KB Output is correct
69 Correct 1754 ms 120724 KB Output is correct
70 Correct 4232 ms 110228 KB Output is correct
71 Correct 4269 ms 110476 KB Output is correct
72 Correct 1877 ms 140668 KB Output is correct
73 Correct 1995 ms 119524 KB Output is correct
74 Correct 2561 ms 113952 KB Output is correct
75 Correct 3878 ms 111632 KB Output is correct
76 Correct 2390 ms 108796 KB Output is correct
77 Correct 2354 ms 107920 KB Output is correct
78 Correct 2635 ms 109700 KB Output is correct
79 Correct 2790 ms 111268 KB Output is correct
80 Correct 2842 ms 109212 KB Output is correct
81 Correct 318 ms 58604 KB Output is correct
82 Correct 307 ms 56796 KB Output is correct
83 Correct 306 ms 54872 KB Output is correct
84 Correct 358 ms 53336 KB Output is correct
85 Correct 377 ms 54748 KB Output is correct
86 Correct 361 ms 51284 KB Output is correct
87 Correct 346 ms 53196 KB Output is correct
88 Correct 337 ms 54620 KB Output is correct
89 Correct 313 ms 51288 KB Output is correct
90 Correct 253 ms 58332 KB Output is correct
91 Correct 328 ms 58716 KB Output is correct
92 Correct 322 ms 55388 KB Output is correct
93 Correct 332 ms 54236 KB Output is correct
94 Correct 309 ms 51672 KB Output is correct
95 Correct 341 ms 50652 KB Output is correct
96 Correct 238 ms 49500 KB Output is correct
97 Correct 1866 ms 141488 KB Output is correct
98 Correct 1451 ms 93836 KB Output is correct
99 Correct 4478 ms 104004 KB Output is correct
100 Correct 1826 ms 132720 KB Output is correct
101 Correct 1801 ms 122512 KB Output is correct
102 Correct 4485 ms 112784 KB Output is correct
103 Correct 3436 ms 100020 KB Output is correct
104 Correct 3510 ms 99676 KB Output is correct
105 Correct 2826 ms 98704 KB Output is correct
106 Correct 2914 ms 98620 KB Output is correct
107 Correct 2139 ms 114868 KB Output is correct
108 Correct 2121 ms 121868 KB Output is correct
109 Correct 2121 ms 105104 KB Output is correct
110 Correct 1911 ms 114448 KB Output is correct
111 Correct 1912 ms 121360 KB Output is correct
112 Correct 1843 ms 104336 KB Output is correct
113 Correct 1340 ms 140216 KB Output is correct
114 Correct 1955 ms 141968 KB Output is correct
115 Correct 2013 ms 125596 KB Output is correct
116 Correct 2092 ms 118764 KB Output is correct
117 Correct 2147 ms 106456 KB Output is correct
118 Correct 2017 ms 100880 KB Output is correct
119 Correct 1563 ms 95988 KB Output is correct
120 Correct 1685 ms 94604 KB Output is correct
121 Correct 2032 ms 97040 KB Output is correct
122 Correct 2149 ms 96780 KB Output is correct
123 Correct 2151 ms 98060 KB Output is correct
124 Correct 1988 ms 99088 KB Output is correct
125 Correct 2459 ms 98528 KB Output is correct
126 Correct 1842 ms 98960 KB Output is correct