#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[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};
}
for(int i=1;i<=k;i++)
sort(pos[i].begin(),pos[i].end());
for(int i=1;i<=q;i++)
{
int x,y;
cin>>x>>y;
qr[x].push_back(i);
}
}
int ans[maxn];
vector<int> change[maxv];
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[nxt].push_back(i);
}
for(int i=1;i<=1e1;i++)
{
for(int j=0;j<change[i].size();j++)
{
int x=change[i][j];
//cout<<i<<" -> "<<x<<endl;
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[(nw+nxt+1)/2].push_back(x);
}
//cout<<old<<" "<<nw<<endl;
}
/*cout<<i<<": ";
for(auto it=curr.begin();it!=curr.end();it++)
cout<<*it<<" ";
cout<<endl;*/
//cout<<i<<" "<<*curr.begin()<<" "<<*curr.cend()<<endl;
int here=max(i-*curr.begin(),*curr.rbegin()-i);
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 solve()':
new_home.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j=0;j<change[i].size();j++)
| ~^~~~~~~~~~~~~~~~~
new_home.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | if(idx[x]!=pos[x].size()-1)
| ~~~~~~^~~~~~~~~~~~~~~~~
new_home.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int j=0;j<qr[i].size();j++)
| ~^~~~~~~~~~~~~
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status