#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 1000007
using namespace std;
const int bucket_sz=700,inf=1e9+7;
int n,k,q,x,t,l,r,pt,ans[MAXN];
struct event{
int x,type,tim,id;
inline friend bool operator < (event fr,event sc){
if(fr.tim!=sc.tim)return fr.tim<sc.tim;
else return fr.type<sc.type;
}
}s[MAXN];
bool cmp(event fr,event sc){
return fr.x<sc.x;
}
multiset<int> stores[MAXN];
set< pair<int,int> > ss;
vector< pair<int,int> > st,ts;
vector<event> z,ask;
int sp[MAXN],tim;
vector<int> poss;
priority_queue<int> pq;
int mins(){
pair<int,int> p=*ss.begin();
return p.first;
}
int maxs(){
pair<int,int> p=*ss.rbegin();
return p.first;
}
int calc(int x,int t){
if(stores[t].empty())return inf;
auto it=stores[t].lower_bound(x);
int p1=-inf,p2=-inf;
if(it!=stores[t].end())p1=*it;
if(it!=stores[t].begin()){
it--; p2=*it;
}
return min(abs(x-p1),abs(x-p2));
}
void solve(){
tim++; ask.clear();
for(event e:z){
if(e.type==0 or e.type==2){
sp[e.id]=tim;
}else{
ask.push_back(e);
}
}
poss.clear(); st.clear(); ts.clear();
for(int i=1;i<=k;i++){
if(sp[i]==tim)poss.push_back(i);
else{
vector<int> w;
for(int f:stores[i]){
w.push_back(f);
}
if(w.empty()){
st.push_back({0,inf});
ts.push_back({inf,2*inf});
break;
}
st.push_back({0,w[0]});
for(int f=0;f<w.size()-1;f++){
int pos=(w[f]+w[f+1])/2+(w[f]+w[f+1])%2;
int val=(w[f+1]-w[f])/2;
st.push_back({pos,pos+val});
ts.push_back({pos-(w[f]+w[f+1])%2,val-(pos-(w[f]+w[f+1])%2)});
}
ts.push_back({inf,-w.back()});
}
}
if(!st.empty()){
sort(st.begin(),st.end());
sort(ts.begin(),ts.end());
sort(ask.begin(),ask.end(),cmp);
int pt=0;
while(!pq.empty())pq.pop();
for(int i=0;i<ask.size();i++){
while(pt<st.size() and st[pt].first<=ask[i].x){
pq.push(st[pt].second);
pt++;
}
ans[ask[i].id]=max(ans[ask[i].id],pq.top()-ask[i].x);
}
pt=ts.size()-1;
while(!pq.empty())pq.pop();
for(int i=ask.size()-1;i>=0;i--){
while(pt>=0 and ts[pt].first>=ask[i].x){
pq.push(ts[pt].second);
pt--;
}
ans[ask[i].id]=max(ans[ask[i].id],pq.top()+ask[i].x);
}
}
for(event e:z){
if(e.type==0){
stores[e.id].insert(e.x);
}else if(e.type==2){
stores[e.id].erase(stores[e.id].find(e.x));
}else{
for(int i:poss){
ans[e.id]=max(ans[e.id],calc(e.x,i));
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>q;
for(int i=1;i<=n;i++){
cin>>x>>t>>l>>r;
pt++; s[pt]={x,0,l,t};
pt++; s[pt]={x,2,r,t};
}
for(int i=1;i<=q;i++){
cin>>x>>t;
pt++; s[pt]={x,1,t,i};
}
sort(s+1,s+pt+1);
for(int i=1;i<=pt;i++){
z.push_back(s[i]);
if(z.size()==bucket_sz){
solve(); z.clear();
}
}
if(!z.empty()){
solve(); z.clear();
}
for(int i=1;i<=q;i++){
if(ans[i]>200000000)cout<<"-1\n";
else cout<<ans[i]<<"\n";
}
return 0;
}
/*
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
*/
Compilation message
new_home.cpp: In function 'void solve()':
new_home.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int f=0;f<w.size()-1;f++){
| ~^~~~~~~~~~~
new_home.cpp:106:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i=0;i<ask.size();i++){
| ~^~~~~~~~~~~
new_home.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | while(pt<st.size() and st[pt].first<=ask[i].x){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47448 KB |
Output is correct |
4 |
Correct |
19 ms |
47700 KB |
Output is correct |
5 |
Correct |
20 ms |
47456 KB |
Output is correct |
6 |
Correct |
19 ms |
47472 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
19 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47452 KB |
Output is correct |
10 |
Correct |
25 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47452 KB |
Output is correct |
14 |
Correct |
20 ms |
47452 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
20 ms |
47448 KB |
Output is correct |
18 |
Correct |
21 ms |
47452 KB |
Output is correct |
19 |
Correct |
21 ms |
47452 KB |
Output is correct |
20 |
Correct |
20 ms |
47324 KB |
Output is correct |
21 |
Correct |
21 ms |
47452 KB |
Output is correct |
22 |
Correct |
23 ms |
47452 KB |
Output is correct |
23 |
Correct |
21 ms |
47452 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
21 ms |
47452 KB |
Output is correct |
26 |
Correct |
20 ms |
47452 KB |
Output is correct |
27 |
Correct |
23 ms |
47448 KB |
Output is correct |
28 |
Correct |
22 ms |
47396 KB |
Output is correct |
29 |
Correct |
20 ms |
47448 KB |
Output is correct |
30 |
Correct |
21 ms |
47452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47448 KB |
Output is correct |
4 |
Correct |
19 ms |
47700 KB |
Output is correct |
5 |
Correct |
20 ms |
47456 KB |
Output is correct |
6 |
Correct |
19 ms |
47472 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
19 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47452 KB |
Output is correct |
10 |
Correct |
25 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47452 KB |
Output is correct |
14 |
Correct |
20 ms |
47452 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
20 ms |
47448 KB |
Output is correct |
18 |
Correct |
21 ms |
47452 KB |
Output is correct |
19 |
Correct |
21 ms |
47452 KB |
Output is correct |
20 |
Correct |
20 ms |
47324 KB |
Output is correct |
21 |
Correct |
21 ms |
47452 KB |
Output is correct |
22 |
Correct |
23 ms |
47452 KB |
Output is correct |
23 |
Correct |
21 ms |
47452 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
21 ms |
47452 KB |
Output is correct |
26 |
Correct |
20 ms |
47452 KB |
Output is correct |
27 |
Correct |
23 ms |
47448 KB |
Output is correct |
28 |
Correct |
22 ms |
47396 KB |
Output is correct |
29 |
Correct |
20 ms |
47448 KB |
Output is correct |
30 |
Correct |
21 ms |
47452 KB |
Output is correct |
31 |
Correct |
1852 ms |
56904 KB |
Output is correct |
32 |
Correct |
238 ms |
53064 KB |
Output is correct |
33 |
Correct |
156 ms |
54352 KB |
Output is correct |
34 |
Correct |
1203 ms |
54724 KB |
Output is correct |
35 |
Correct |
819 ms |
56384 KB |
Output is correct |
36 |
Correct |
175 ms |
56148 KB |
Output is correct |
37 |
Correct |
130 ms |
53568 KB |
Output is correct |
38 |
Correct |
90 ms |
53588 KB |
Output is correct |
39 |
Correct |
79 ms |
53216 KB |
Output is correct |
40 |
Correct |
79 ms |
53328 KB |
Output is correct |
41 |
Correct |
205 ms |
53584 KB |
Output is correct |
42 |
Correct |
147 ms |
53332 KB |
Output is correct |
43 |
Correct |
409 ms |
57404 KB |
Output is correct |
44 |
Correct |
179 ms |
53588 KB |
Output is correct |
45 |
Correct |
124 ms |
53832 KB |
Output is correct |
46 |
Correct |
75 ms |
53584 KB |
Output is correct |
47 |
Correct |
68 ms |
53016 KB |
Output is correct |
48 |
Correct |
64 ms |
53076 KB |
Output is correct |
49 |
Correct |
78 ms |
53328 KB |
Output is correct |
50 |
Correct |
167 ms |
53324 KB |
Output is correct |
51 |
Correct |
72 ms |
53224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5047 ms |
95592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5049 ms |
85532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47448 KB |
Output is correct |
4 |
Correct |
19 ms |
47700 KB |
Output is correct |
5 |
Correct |
20 ms |
47456 KB |
Output is correct |
6 |
Correct |
19 ms |
47472 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
19 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47452 KB |
Output is correct |
10 |
Correct |
25 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47452 KB |
Output is correct |
14 |
Correct |
20 ms |
47452 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
20 ms |
47448 KB |
Output is correct |
18 |
Correct |
21 ms |
47452 KB |
Output is correct |
19 |
Correct |
21 ms |
47452 KB |
Output is correct |
20 |
Correct |
20 ms |
47324 KB |
Output is correct |
21 |
Correct |
21 ms |
47452 KB |
Output is correct |
22 |
Correct |
23 ms |
47452 KB |
Output is correct |
23 |
Correct |
21 ms |
47452 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
21 ms |
47452 KB |
Output is correct |
26 |
Correct |
20 ms |
47452 KB |
Output is correct |
27 |
Correct |
23 ms |
47448 KB |
Output is correct |
28 |
Correct |
22 ms |
47396 KB |
Output is correct |
29 |
Correct |
20 ms |
47448 KB |
Output is correct |
30 |
Correct |
21 ms |
47452 KB |
Output is correct |
31 |
Correct |
1852 ms |
56904 KB |
Output is correct |
32 |
Correct |
238 ms |
53064 KB |
Output is correct |
33 |
Correct |
156 ms |
54352 KB |
Output is correct |
34 |
Correct |
1203 ms |
54724 KB |
Output is correct |
35 |
Correct |
819 ms |
56384 KB |
Output is correct |
36 |
Correct |
175 ms |
56148 KB |
Output is correct |
37 |
Correct |
130 ms |
53568 KB |
Output is correct |
38 |
Correct |
90 ms |
53588 KB |
Output is correct |
39 |
Correct |
79 ms |
53216 KB |
Output is correct |
40 |
Correct |
79 ms |
53328 KB |
Output is correct |
41 |
Correct |
205 ms |
53584 KB |
Output is correct |
42 |
Correct |
147 ms |
53332 KB |
Output is correct |
43 |
Correct |
409 ms |
57404 KB |
Output is correct |
44 |
Correct |
179 ms |
53588 KB |
Output is correct |
45 |
Correct |
124 ms |
53832 KB |
Output is correct |
46 |
Correct |
75 ms |
53584 KB |
Output is correct |
47 |
Correct |
68 ms |
53016 KB |
Output is correct |
48 |
Correct |
64 ms |
53076 KB |
Output is correct |
49 |
Correct |
78 ms |
53328 KB |
Output is correct |
50 |
Correct |
167 ms |
53324 KB |
Output is correct |
51 |
Correct |
72 ms |
53224 KB |
Output is correct |
52 |
Correct |
93 ms |
57888 KB |
Output is correct |
53 |
Correct |
71 ms |
54728 KB |
Output is correct |
54 |
Correct |
107 ms |
57592 KB |
Output is correct |
55 |
Correct |
1200 ms |
55444 KB |
Output is correct |
56 |
Correct |
1501 ms |
56016 KB |
Output is correct |
57 |
Correct |
551 ms |
54256 KB |
Output is correct |
58 |
Correct |
787 ms |
55120 KB |
Output is correct |
59 |
Correct |
984 ms |
55832 KB |
Output is correct |
60 |
Correct |
381 ms |
54184 KB |
Output is correct |
61 |
Correct |
520 ms |
57796 KB |
Output is correct |
62 |
Correct |
582 ms |
58068 KB |
Output is correct |
63 |
Correct |
1425 ms |
57040 KB |
Output is correct |
64 |
Correct |
1824 ms |
56284 KB |
Output is correct |
65 |
Correct |
1066 ms |
54608 KB |
Output is correct |
66 |
Correct |
322 ms |
53584 KB |
Output is correct |
67 |
Correct |
481 ms |
52752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47448 KB |
Output is correct |
4 |
Correct |
19 ms |
47700 KB |
Output is correct |
5 |
Correct |
20 ms |
47456 KB |
Output is correct |
6 |
Correct |
19 ms |
47472 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
19 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47452 KB |
Output is correct |
10 |
Correct |
25 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47452 KB |
Output is correct |
14 |
Correct |
20 ms |
47452 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
20 ms |
47448 KB |
Output is correct |
18 |
Correct |
21 ms |
47452 KB |
Output is correct |
19 |
Correct |
21 ms |
47452 KB |
Output is correct |
20 |
Correct |
20 ms |
47324 KB |
Output is correct |
21 |
Correct |
21 ms |
47452 KB |
Output is correct |
22 |
Correct |
23 ms |
47452 KB |
Output is correct |
23 |
Correct |
21 ms |
47452 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
21 ms |
47452 KB |
Output is correct |
26 |
Correct |
20 ms |
47452 KB |
Output is correct |
27 |
Correct |
23 ms |
47448 KB |
Output is correct |
28 |
Correct |
22 ms |
47396 KB |
Output is correct |
29 |
Correct |
20 ms |
47448 KB |
Output is correct |
30 |
Correct |
21 ms |
47452 KB |
Output is correct |
31 |
Correct |
1852 ms |
56904 KB |
Output is correct |
32 |
Correct |
238 ms |
53064 KB |
Output is correct |
33 |
Correct |
156 ms |
54352 KB |
Output is correct |
34 |
Correct |
1203 ms |
54724 KB |
Output is correct |
35 |
Correct |
819 ms |
56384 KB |
Output is correct |
36 |
Correct |
175 ms |
56148 KB |
Output is correct |
37 |
Correct |
130 ms |
53568 KB |
Output is correct |
38 |
Correct |
90 ms |
53588 KB |
Output is correct |
39 |
Correct |
79 ms |
53216 KB |
Output is correct |
40 |
Correct |
79 ms |
53328 KB |
Output is correct |
41 |
Correct |
205 ms |
53584 KB |
Output is correct |
42 |
Correct |
147 ms |
53332 KB |
Output is correct |
43 |
Correct |
409 ms |
57404 KB |
Output is correct |
44 |
Correct |
179 ms |
53588 KB |
Output is correct |
45 |
Correct |
124 ms |
53832 KB |
Output is correct |
46 |
Correct |
75 ms |
53584 KB |
Output is correct |
47 |
Correct |
68 ms |
53016 KB |
Output is correct |
48 |
Correct |
64 ms |
53076 KB |
Output is correct |
49 |
Correct |
78 ms |
53328 KB |
Output is correct |
50 |
Correct |
167 ms |
53324 KB |
Output is correct |
51 |
Correct |
72 ms |
53224 KB |
Output is correct |
52 |
Execution timed out |
5047 ms |
95592 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |