#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define ep insert
#define pow pwr
#define sqrt sqrtt
#define elif else if
using namespace std;
const int N=1e6+5;
int n,k,q,d[N];
pair<pair<int,int>,pair<int,int>> a[N];
vector<pair<int,int>> adj[2][N];
map<int,int> mp;
multiset<int> s[N];
pair<pair<int,int>,int> b[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>k>>q;
for (int i=1;i<=n;i++){
cin>>a[i].F.F>>a[i].F.S>>a[i].S.F>>a[i].S.S;
mp[a[i].S.F]++;
mp[a[i].S.S]++;
}
int c=1;
for (int i=1;i<=q;i++){
cin>>b[i].F.S>>b[i].F.F;
mp[b[i].F.F]++;
b[i].S=i;
}
for (auto u:mp){
mp[u.F]=c;
c++;
}
for (int i=1;i<=n;i++){
a[i].S.F=mp[a[i].S.F];
a[i].S.S=mp[a[i].S.S];
adj[0][a[i].S.F].pb(a[i].F);
adj[1][a[i].S.S].pb(a[i].F);
}
for (int i=1;i<=q;i++) b[i].F.F=mp[b[i].F.F];
sort(b+1,b+1+q);
int j=1;
for (int i=1;i<c;i++){
for (auto u:adj[0][i]) s[u.S].ep(u.F);
while (b[j].F.F<i) j++;
while (b[j].F.F==i){
int ans=INT_MIN;
for (int l=1;l<=k;l++){
if (s[l].empty()){
ans=INT_MAX;
break;
}
int ansx=INT_MAX;
auto it=s[l].lower_bound(b[j].F.S);
if (it!=s[l].end()) ansx=min(ansx,*it-b[j].F.S);
if (it!=s[l].begin()) --it;
if (it!=s[l].end()) ansx=min(ansx,*it-b[j].F.S);
ans=max(ans,ansx);
}
if (ans==INT_MAX) ans=-1;
d[b[j].S]=ans;
j++;
}
for (auto u:adj[1][i]) s[u.S].erase(s[u.S].find(u.F));
}
for (int i=1;i<=q;i++) cout<<d[i]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94308 KB |
Output is correct |
2 |
Correct |
46 ms |
94164 KB |
Output is correct |
3 |
Correct |
44 ms |
94192 KB |
Output is correct |
4 |
Incorrect |
46 ms |
94164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94308 KB |
Output is correct |
2 |
Correct |
46 ms |
94164 KB |
Output is correct |
3 |
Correct |
44 ms |
94192 KB |
Output is correct |
4 |
Incorrect |
46 ms |
94164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5039 ms |
136720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5053 ms |
157676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94308 KB |
Output is correct |
2 |
Correct |
46 ms |
94164 KB |
Output is correct |
3 |
Correct |
44 ms |
94192 KB |
Output is correct |
4 |
Incorrect |
46 ms |
94164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94308 KB |
Output is correct |
2 |
Correct |
46 ms |
94164 KB |
Output is correct |
3 |
Correct |
44 ms |
94192 KB |
Output is correct |
4 |
Incorrect |
46 ms |
94164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |