#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const int M = 7e6 + 5;
const int MX = 1e8 + 5;
struct ST{
multiset<int> tree[M][2];
int f[M][2], last;
ST(){
last = 0;
}
void make(int x){
if(!f[x][0]) f[x][0] = ++last;
if(!f[x][1]) f[x][1] = ++last;
}
void add(int l, int r, int s, int t, int lx = 0, int rx = MX, int x = 0){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
if(t == 1){
tree[x][0].insert(s + (lx - l));
//~ tree[x][0] = max(tree[x][0], s + (lx - l));
} else {
tree[x][1].insert(s - (lx - l));
//~ tree[x][1] = max(tree[x][1], s - (lx - l));
} return;
} int m = (lx + rx) >> 1;
make(x);
add(l, r, s, t, lx, m, f[x][0]), add(l, r, s, t, m+1, rx, f[x][1]);
}
int get(int i, int lx = 0, int rx = MX, int x = 0){
int res = 0;
if(!tree[x][0].empty()) res = max(res, (*--tree[x][0].end()) + (i - lx));
if(!tree[x][1].empty()) res = max(res, (*--tree[x][1].end()) - (i - lx));
if(lx == rx) return res;
int m = (lx + rx) >> 1;
if(i <= m) return max((f[x][0] ? get(i, lx, m, f[x][0]) : 0ll), res);
else return max((f[x][1] ? get(i, m+1, rx, f[x][1]) : 0ll), res);
}
}tree;
const int N = 3e5 + 5;
int x[N], t[N], a[N], b[N], l[N], y[N];
vector<int> stor[N];
/*
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::sync_with_stdio(0); cin.tie(0);
int n, k, q; cin>>n>>k>>q;
for(int i=0;i<n;i++){
cin>>x[i]>>t[i]>>a[i]>>b[i];
stor[--t[i]].push_back(i);
}
bool is = 1;
for(int i=0;i<k;i++){
if(stor[i].empty()) { is = 0; break; }
sort(stor[i].begin(), stor[i].end(), [&](int i, int j){
return (x[i] < x[j]);
});
for(int j=1;j<(int)stor[i].size();j++){
int l = x[stor[i][j-1]], r = x[stor[i][j]];
if(l == r) continue;
int m = (l + r) >> 1;
tree.add(l, m, 0, 1);
tree.add(m + 1, r, r - m - 1, -1);
}
tree.add(0, x[stor[i][0]], x[stor[i][0]], -1);
tree.add(x[stor[i].back()], MX, 0, 1);
}
while(q--){
int l, y;
cin>>l>>y;
if(is){
cout<<tree.get(l)<<"\n";
} else {
cout<<-1<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
664920 KB |
Output is correct |
2 |
Incorrect |
287 ms |
664868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
664920 KB |
Output is correct |
2 |
Incorrect |
287 ms |
664868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2904 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2492 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
664920 KB |
Output is correct |
2 |
Incorrect |
287 ms |
664868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
664920 KB |
Output is correct |
2 |
Incorrect |
287 ms |
664868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |