#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return 1; } return 0; }
const int N = 3e5+5;
const int mod = 1e9+7;
const long long inf = 1e18+7;
int n, m, k, a[N];
int x[N], t[N], b[N], l[N], y[N], rr[N];
set<int> ss[N];
void solve(){
cin>>n>>k>>m;
for(int i=1;i<=n;i++) cin>>x[i]>>t[i]>>a[i]>>b[i];
for(int i=1;i<=m;i++) cin>>l[i]>>y[i];
vector<array<int, 4>> tt;
for(int i=1;i<=m;i++) tt.pb({a[i], -1, t[i], x[i]}), tt.pb({b[i], 1, t[i], x[i]});
for(int i=1;i<=n;i++) tt.pb({y[i], 0, l[i], i});
memset(rr, -2, sizeof rr);
sort(all(tt));
for(int i=0;i<sz(tt);){
int j = i;
while(j < sz(tt) && tt[j][0] == tt[i][0]) j++;
for(int l=i;l<j;l++){
if(tt[l][1] == -1){
int in = tt[l][3], t = tt[l][2];
ss[t].insert(in);
}
} for(int l=i;l<j;l++){
if(tt[l][1] == 0) {
int in = tt[l][2], ri = tt[l][3];
for(int t=1;t<=k;t++){
if(ss[t].empty()) { rr[ri] = -1; break; }
auto it = ss[t].lb(in);
int trr = inf;
if(it != ss[t].end()) umin(trr, abs(*it - in));
it = ss[t].ub(in);
if(it != ss[t].begin()) --it, umin(trr, abs(*it - in));
umax(rr[ri], trr);
}
}
} for(int l=i;l<j;l++){
if(tt[l][1] == 1) {
int in = tt[l][3], t = tt[l][2];
ss[t].erase(in);
}
} i = j;
} for(int i=1;i<=n;i++) assert(rr[i] >= -1);
for(int i=1;i<=n;i++) cout<<rr[i]<<" ";
}
/*
1 1 1
1000000000 1 1 1
1 1
2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7
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
*/
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
16760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
16760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5079 ms |
73044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5088 ms |
73060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
16760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
16760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |