#include <bits/stdc++.h>
using namespace std;
const int maxv=1e8;
const int maxn=3*1e5;
int n,q,k;
vector<int> pos[maxn];
struct store
{
int x,a,b,t;
store(){}
store(int _x,int _t,int _a,int _b)
{
x=_x;
t=_t;
a=_a;
b=_b;
}
};
store s[maxn];
vector<int> qr[10*maxn];
vector<int> all;
map<int,int> opp,oppopp;
int val[maxn];
void read()
{
cin>>n>>k>>q;
for(int i=1;i<=n;i++)
{
int x,a,b,t;
cin>>x>>t>>a>>b;
pos[t].push_back(x);
s[i]={x,t,a,b};
all.push_back(x);
}
for(int i=1;i<=k;i++)
{
sort(pos[i].begin(),pos[i].end());
for(int j=0;j<pos[i].size()-1;j++)
{
int sect=(pos[i][j]+pos[i][j+1]+1)/2;
all.push_back(sect);
}
}
for(int i=1;i<=q;i++)
{
int x,y;
cin>>x>>y;
val[i]=x;
//qr[x].push_back(i);
all.push_back(x);
}
sort(all.begin(),all.end());
for(int i=0;i<all.size();i++)
opp[all[i]]=i+1,oppopp[i+1]=all[i];
for(int i=1;i<=q;i++)
{
qr[opp[val[i]]].push_back(i);
}
}
int ans[maxn];
vector<int> change[maxn];
multiset<int> curr;
int idx[maxn];
void solve()
{
for(int i=1;i<=k;i++)
{
curr.insert(pos[i][0]);
if(pos[i].size()==0)continue;
int x=pos[i][0],y=pos[i][1];
int nxt=(y+x+1)/2;
change[opp[nxt]].push_back(i);
}
for(int i=1;i<=all.size();i++)
{
for(int j=0;j<change[i].size();j++)
{
int x=change[i][j];
int old=pos[x][idx[x]];
curr.erase(curr.find(old));
idx[x]++;
int nw=pos[x][idx[x]];
curr.insert(nw);
if(idx[x]!=pos[x].size()-1)
{
int nxt=pos[x][idx[x]+1];
change[opp[(nw+nxt+1)/2]].push_back(x);
}
}
int h=oppopp[i];
int here=max(h-*curr.begin(),*curr.rbegin()-h);
for(int j=0;j<qr[i].size();j++)
{
ans[qr[i][j]]=here;
}
}
for(int i=1;i<=q;i++)
cout<<ans[i]<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
read();
solve();
return 0;
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
1 1
5 1
6 1
10 1
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
1 1
5 1
6 1
10 1 4 2 4
4 -> 1
8 -> 2
1
1
2
10
*/
Compilation message
new_home.cpp: In function 'void read()':
new_home.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int j=0;j<pos[i].size()-1;j++)
| ~^~~~~~~~~~~~~~~~
new_home.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i<all.size();i++)
| ~^~~~~~~~~~~
new_home.cpp: In function 'void solve()':
new_home.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=1;i<=all.size();i++)
| ~^~~~~~~~~~~~
new_home.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int j=0;j<change[i].size();j++)
| ~^~~~~~~~~~~~~~~~~
new_home.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | if(idx[x]!=pos[x].size()-1)
| ~~~~~~^~~~~~~~~~~~~~~~~
new_home.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int j=0;j<qr[i].size();j++)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
87640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
87640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
859 ms |
376564 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1008 ms |
404044 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
87640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
87640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |