#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
class Point;
class Query{
public:
int x;
int y;
int ind;
Query() : x(0), y(0) {}
Query(int xx, int yy, int i) : x(xx), y(yy), ind(i) {}
bool operator<(const Query& other) const {
if(y==other.y){
if(x==other.x)return ind<other.ind;
return x<other.x;
}
return y<other.y;
}
bool operator<(const Point& other) const;
};
class Point {
public:
int x;
int t;
int a;
int b;
bool is_erase;
Point() : x(0), t(0), a(0), b(0) {}
Point(int xx, int tt, int aa, int bb, bool er) :
x(xx), t(tt), a(aa), b(bb), is_erase(er) {}
bool operator<(const Point& other) const {
if(other.a==a){
if(other.b==b){
if(other.x==x){
return t<other.t;
}
return x<other.x;
}
return b<other.b;
}
return a<other.a;
}
bool operator<(const Query& other) const {
return a<=other.y;
}
};
bool Query::operator<(const Point& other) const {
return this->y<other.a;
}
class Node {
public:
Query q;
Point p;
bool is_q;
Node(Query qq) : q(qq) {
is_q=true;
}
Node(Point pp) : p(pp) {
is_q=false;
}
bool operator<(const Node& other) const {
if(is_q && other.is_q)return q<other.q;
if(is_q) return q<other.p;
if(other.is_q) return p<other.q;
return p<other.p;
}
};
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=3e5+7;
ll n,m,k;
multiset<int>d[N];
vector<Node>s;
int calc_ans(int x){
int ans=0;
for(int i=1;i<=k;i++){
if(d[i].size()==0)return -1;
auto it=d[i].lower_bound(x);
int fd=MOD,sd=MOD;
if(it!=d[i].end()){
fd=*it-x;
}
if(it!=d[i].begin()){
it--;
sd=x-*it;
}
ans=max(ans,min(fd,sd));
}
return ans;
}
int main() {
cin>>n>>k>>m;
for(int i=0;i<n;i++){
int x,t,a,b;
cin>>x>>t>>a>>b;
s.push_back(Node(Point(x,t,a,b,false)));
s.push_back(Node(Point(x,t,b+1,b,true)));
}
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
s.push_back(Node(Query(x,y,i)));
}
sort(s.begin(),s.end());
vector<int>ans(m,-1);
for(int i=0;i<s.size();i++){
if(s[i].is_q){
ans[s[i].q.ind] = calc_ans(s[i].q.x);
}
else{
if(s[i].p.is_erase){
d[s[i].p.t].erase(d[s[i].p.t].find(s[i].p.x));
}
else{
d[s[i].p.t].insert(s[i].p.x);
}
}
}
for(int x:ans)cout<<x<<"\n";
cout<<endl;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:119:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
7 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14404 KB |
Output is correct |
6 |
Correct |
8 ms |
14492 KB |
Output is correct |
7 |
Correct |
8 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14532 KB |
Output is correct |
9 |
Correct |
7 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14412 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
8 ms |
14420 KB |
Output is correct |
13 |
Correct |
12 ms |
14548 KB |
Output is correct |
14 |
Correct |
8 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
10 ms |
14524 KB |
Output is correct |
17 |
Correct |
8 ms |
14420 KB |
Output is correct |
18 |
Correct |
8 ms |
14404 KB |
Output is correct |
19 |
Correct |
8 ms |
14408 KB |
Output is correct |
20 |
Correct |
8 ms |
14400 KB |
Output is correct |
21 |
Correct |
7 ms |
14400 KB |
Output is correct |
22 |
Correct |
8 ms |
14524 KB |
Output is correct |
23 |
Correct |
8 ms |
14412 KB |
Output is correct |
24 |
Correct |
8 ms |
14408 KB |
Output is correct |
25 |
Correct |
8 ms |
14420 KB |
Output is correct |
26 |
Correct |
7 ms |
14420 KB |
Output is correct |
27 |
Correct |
7 ms |
14488 KB |
Output is correct |
28 |
Correct |
7 ms |
14420 KB |
Output is correct |
29 |
Correct |
7 ms |
14420 KB |
Output is correct |
30 |
Correct |
7 ms |
14400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
7 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14404 KB |
Output is correct |
6 |
Correct |
8 ms |
14492 KB |
Output is correct |
7 |
Correct |
8 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14532 KB |
Output is correct |
9 |
Correct |
7 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14412 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
8 ms |
14420 KB |
Output is correct |
13 |
Correct |
12 ms |
14548 KB |
Output is correct |
14 |
Correct |
8 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
10 ms |
14524 KB |
Output is correct |
17 |
Correct |
8 ms |
14420 KB |
Output is correct |
18 |
Correct |
8 ms |
14404 KB |
Output is correct |
19 |
Correct |
8 ms |
14408 KB |
Output is correct |
20 |
Correct |
8 ms |
14400 KB |
Output is correct |
21 |
Correct |
7 ms |
14400 KB |
Output is correct |
22 |
Correct |
8 ms |
14524 KB |
Output is correct |
23 |
Correct |
8 ms |
14412 KB |
Output is correct |
24 |
Correct |
8 ms |
14408 KB |
Output is correct |
25 |
Correct |
8 ms |
14420 KB |
Output is correct |
26 |
Correct |
7 ms |
14420 KB |
Output is correct |
27 |
Correct |
7 ms |
14488 KB |
Output is correct |
28 |
Correct |
7 ms |
14420 KB |
Output is correct |
29 |
Correct |
7 ms |
14420 KB |
Output is correct |
30 |
Correct |
7 ms |
14400 KB |
Output is correct |
31 |
Correct |
1521 ms |
25276 KB |
Output is correct |
32 |
Correct |
96 ms |
24512 KB |
Output is correct |
33 |
Correct |
209 ms |
26036 KB |
Output is correct |
34 |
Correct |
1217 ms |
26032 KB |
Output is correct |
35 |
Correct |
742 ms |
27084 KB |
Output is correct |
36 |
Correct |
221 ms |
26936 KB |
Output is correct |
37 |
Correct |
200 ms |
25904 KB |
Output is correct |
38 |
Correct |
146 ms |
25812 KB |
Output is correct |
39 |
Correct |
139 ms |
25892 KB |
Output is correct |
40 |
Correct |
136 ms |
25904 KB |
Output is correct |
41 |
Correct |
264 ms |
25960 KB |
Output is correct |
42 |
Correct |
222 ms |
26032 KB |
Output is correct |
43 |
Correct |
383 ms |
26636 KB |
Output is correct |
44 |
Correct |
235 ms |
25920 KB |
Output is correct |
45 |
Correct |
164 ms |
25892 KB |
Output is correct |
46 |
Correct |
134 ms |
25808 KB |
Output is correct |
47 |
Correct |
122 ms |
25840 KB |
Output is correct |
48 |
Correct |
119 ms |
25908 KB |
Output is correct |
49 |
Correct |
142 ms |
25884 KB |
Output is correct |
50 |
Correct |
211 ms |
25820 KB |
Output is correct |
51 |
Correct |
133 ms |
25904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5045 ms |
61240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5038 ms |
61340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
7 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14404 KB |
Output is correct |
6 |
Correct |
8 ms |
14492 KB |
Output is correct |
7 |
Correct |
8 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14532 KB |
Output is correct |
9 |
Correct |
7 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14412 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
8 ms |
14420 KB |
Output is correct |
13 |
Correct |
12 ms |
14548 KB |
Output is correct |
14 |
Correct |
8 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
10 ms |
14524 KB |
Output is correct |
17 |
Correct |
8 ms |
14420 KB |
Output is correct |
18 |
Correct |
8 ms |
14404 KB |
Output is correct |
19 |
Correct |
8 ms |
14408 KB |
Output is correct |
20 |
Correct |
8 ms |
14400 KB |
Output is correct |
21 |
Correct |
7 ms |
14400 KB |
Output is correct |
22 |
Correct |
8 ms |
14524 KB |
Output is correct |
23 |
Correct |
8 ms |
14412 KB |
Output is correct |
24 |
Correct |
8 ms |
14408 KB |
Output is correct |
25 |
Correct |
8 ms |
14420 KB |
Output is correct |
26 |
Correct |
7 ms |
14420 KB |
Output is correct |
27 |
Correct |
7 ms |
14488 KB |
Output is correct |
28 |
Correct |
7 ms |
14420 KB |
Output is correct |
29 |
Correct |
7 ms |
14420 KB |
Output is correct |
30 |
Correct |
7 ms |
14400 KB |
Output is correct |
31 |
Correct |
1521 ms |
25276 KB |
Output is correct |
32 |
Correct |
96 ms |
24512 KB |
Output is correct |
33 |
Correct |
209 ms |
26036 KB |
Output is correct |
34 |
Correct |
1217 ms |
26032 KB |
Output is correct |
35 |
Correct |
742 ms |
27084 KB |
Output is correct |
36 |
Correct |
221 ms |
26936 KB |
Output is correct |
37 |
Correct |
200 ms |
25904 KB |
Output is correct |
38 |
Correct |
146 ms |
25812 KB |
Output is correct |
39 |
Correct |
139 ms |
25892 KB |
Output is correct |
40 |
Correct |
136 ms |
25904 KB |
Output is correct |
41 |
Correct |
264 ms |
25960 KB |
Output is correct |
42 |
Correct |
222 ms |
26032 KB |
Output is correct |
43 |
Correct |
383 ms |
26636 KB |
Output is correct |
44 |
Correct |
235 ms |
25920 KB |
Output is correct |
45 |
Correct |
164 ms |
25892 KB |
Output is correct |
46 |
Correct |
134 ms |
25808 KB |
Output is correct |
47 |
Correct |
122 ms |
25840 KB |
Output is correct |
48 |
Correct |
119 ms |
25908 KB |
Output is correct |
49 |
Correct |
142 ms |
25884 KB |
Output is correct |
50 |
Correct |
211 ms |
25820 KB |
Output is correct |
51 |
Correct |
133 ms |
25904 KB |
Output is correct |
52 |
Correct |
149 ms |
26952 KB |
Output is correct |
53 |
Correct |
145 ms |
26104 KB |
Output is correct |
54 |
Correct |
182 ms |
26964 KB |
Output is correct |
55 |
Execution timed out |
5045 ms |
25980 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
7 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14404 KB |
Output is correct |
6 |
Correct |
8 ms |
14492 KB |
Output is correct |
7 |
Correct |
8 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14532 KB |
Output is correct |
9 |
Correct |
7 ms |
14420 KB |
Output is correct |
10 |
Correct |
8 ms |
14412 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
8 ms |
14420 KB |
Output is correct |
13 |
Correct |
12 ms |
14548 KB |
Output is correct |
14 |
Correct |
8 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
10 ms |
14524 KB |
Output is correct |
17 |
Correct |
8 ms |
14420 KB |
Output is correct |
18 |
Correct |
8 ms |
14404 KB |
Output is correct |
19 |
Correct |
8 ms |
14408 KB |
Output is correct |
20 |
Correct |
8 ms |
14400 KB |
Output is correct |
21 |
Correct |
7 ms |
14400 KB |
Output is correct |
22 |
Correct |
8 ms |
14524 KB |
Output is correct |
23 |
Correct |
8 ms |
14412 KB |
Output is correct |
24 |
Correct |
8 ms |
14408 KB |
Output is correct |
25 |
Correct |
8 ms |
14420 KB |
Output is correct |
26 |
Correct |
7 ms |
14420 KB |
Output is correct |
27 |
Correct |
7 ms |
14488 KB |
Output is correct |
28 |
Correct |
7 ms |
14420 KB |
Output is correct |
29 |
Correct |
7 ms |
14420 KB |
Output is correct |
30 |
Correct |
7 ms |
14400 KB |
Output is correct |
31 |
Correct |
1521 ms |
25276 KB |
Output is correct |
32 |
Correct |
96 ms |
24512 KB |
Output is correct |
33 |
Correct |
209 ms |
26036 KB |
Output is correct |
34 |
Correct |
1217 ms |
26032 KB |
Output is correct |
35 |
Correct |
742 ms |
27084 KB |
Output is correct |
36 |
Correct |
221 ms |
26936 KB |
Output is correct |
37 |
Correct |
200 ms |
25904 KB |
Output is correct |
38 |
Correct |
146 ms |
25812 KB |
Output is correct |
39 |
Correct |
139 ms |
25892 KB |
Output is correct |
40 |
Correct |
136 ms |
25904 KB |
Output is correct |
41 |
Correct |
264 ms |
25960 KB |
Output is correct |
42 |
Correct |
222 ms |
26032 KB |
Output is correct |
43 |
Correct |
383 ms |
26636 KB |
Output is correct |
44 |
Correct |
235 ms |
25920 KB |
Output is correct |
45 |
Correct |
164 ms |
25892 KB |
Output is correct |
46 |
Correct |
134 ms |
25808 KB |
Output is correct |
47 |
Correct |
122 ms |
25840 KB |
Output is correct |
48 |
Correct |
119 ms |
25908 KB |
Output is correct |
49 |
Correct |
142 ms |
25884 KB |
Output is correct |
50 |
Correct |
211 ms |
25820 KB |
Output is correct |
51 |
Correct |
133 ms |
25904 KB |
Output is correct |
52 |
Execution timed out |
5045 ms |
61240 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |