#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
int X[300005];
int type[300005];
int A[300005];
int B[300005];
int L[300005];
int Y[300005];
int ans[300005];
int state_a[300005];
int state_b[300005];
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, K, Q;
cin >> N >> K >> Q;
int i, j;
for(i=0;i<N;i++) cin >> X[i] >> type[i] >> A[i] >> B[i];
for(i=0;i<N;i++) type[i]--;
for(i=0;i<Q;i++) cin >> L[i] >> Y[i];
if(N<=60000&&Q<=60000&&K<=400) {
vector<map<int,int>> S;
S.resize(K);
map<int,vector<P>> In;
map<int,vector<P>> Out;
for(i=0;i<N;i++) {
In[A[i]].push_back(P(type[i],X[i]));
Out[B[i]].push_back(P(type[i],X[i]));
}
map<int,vector<P>> Query;
for(i=0;i<Q;i++) {
Query[Y[i]].push_back(P(L[i],i));
}
vector<int> idx;
for(i=0;i<Q;i++) idx.push_back(Y[i]);
for(i=0;i<N;i++) {
idx.push_back(A[i]);
idx.push_back(B[i]);
}
sort(idx.begin(),idx.end());
idx.erase(unique(idx.begin(),idx.end()),idx.end());
for(i=0;i<idx.size();i++) {
for(P k : In[idx[i]]) {
S[k.first][k.second]++;
//S[k.first].insert(k.second);
}
for(P k : Query[idx[i]]) {
int ma = 0;
int pos = k.first;
for(j=0;j<K;j++) {
int dis = 1e18;
auto it = S[j].lower_bound(pos);
if(it != S[j].end()) dis = min(dis, it->first - pos);
if(it != S[j].begin()) {
it--;
dis = min(dis, pos - it->first);
}
ma = max(ma, dis);
}
ans[k.second] = (ma > 1e9 ? -1 : ma);
}
for(P k : Out[idx[i]]) {
S[k.first][k.second]--;
if(S[k.first][k.second]==0) {
S[k.first].erase(k.second);
}
}
}
for(i=0;i<Q;i++) cout << ans[i] << '\n';
return 0;
}
vector<vector<int>> V;
V.resize(K);
for(i=0;i<N;i++) V[type[i]].push_back(X[i]);
for(i=0;i<K;i++) sort(V[i].begin(),V[i].end());
bool emp = false;
for(i=0;i<K;i++) {
if(V[i].size()==0) emp = true;
}
if(emp) {
for(i=0;i<Q;i++) cout << "-1\n";
return 0;
}
map<int,int> Minus, Plus;
for(i=0;i<K;i++) {
state_a[i] = -1;
state_b[i] = V[i][0];
Minus[state_b[i]]++;
}
map<int,vector<T>> Query;
vector<int> idx;
for(i=0;i<K;i++) {
for(j=0;j<V[i].size();j++) {
Query[V[i][j]].push_back(T(i, 1, -V[i][j]));
idx.push_back(V[i][j]);
}
for(j=0;j+1<V[i].size();j++) {
int mid = (V[i][j] + V[i][j+1] + 1) / 2;
if(mid == V[i][j+1]) continue;
Query[mid].push_back(T(i, -1, V[i][j+1]));
idx.push_back(mid);
}
}
map<int,vector<int>> Qu;
for(i=0;i<Q;i++) {
Qu[L[i]].push_back(i);
idx.push_back(L[i]);
}
sort(idx.begin(),idx.end());
idx.erase(unique(idx.begin(),idx.end()),idx.end());
for(i=0;i<idx.size();i++) {
for(T k : Query[idx[i]]) {
int id = get<0>(k);
int a = get<1>(k);
int b = get<2>(k);
if(state_a[id]==1) {
Plus[state_b[id]]--;
if(Plus[state_b[id]]==0) Plus.erase(state_b[id]);
}
else {
Minus[state_b[id]]--;
if(Minus[state_b[id]]==0) Minus.erase(state_b[id]);
}
state_a[id] = a;
state_b[id] = b;
if(state_a[id]==1) {
Plus[b]++;
}
else {
Minus[b]++;
}
}
for(int m : Qu[idx[i]]) {
int m1 = -1e18;
int m2 = -1e18;
if(!Plus.empty()) m1 = Plus.rbegin()->first;
if(!Minus.empty()) m2 = Minus.rbegin()->first;
ans[m] = max(idx[i] + m1, -idx[i] + m2);
}
}
for(i=0;i<Q;i++) cout << ans[i] << '\n';
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:47:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(i=0;i<idx.size();i++) {
| ~^~~~~~~~~~~
new_home.cpp:98:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(j=0;j<V[i].size();j++) {
| ~^~~~~~~~~~~~
new_home.cpp:102:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(j=0;j+1<V[i].size();j++) {
| ~~~^~~~~~~~~~~~
new_home.cpp:116:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for(i=0;i<idx.size();i++) {
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
720 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
720 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
3462 ms |
58548 KB |
Output is correct |
32 |
Correct |
47 ms |
9536 KB |
Output is correct |
33 |
Correct |
469 ms |
55892 KB |
Output is correct |
34 |
Correct |
2590 ms |
56180 KB |
Output is correct |
35 |
Correct |
1638 ms |
58376 KB |
Output is correct |
36 |
Correct |
513 ms |
58244 KB |
Output is correct |
37 |
Correct |
397 ms |
54896 KB |
Output is correct |
38 |
Correct |
330 ms |
54860 KB |
Output is correct |
39 |
Correct |
278 ms |
54496 KB |
Output is correct |
40 |
Correct |
314 ms |
54584 KB |
Output is correct |
41 |
Correct |
486 ms |
54616 KB |
Output is correct |
42 |
Correct |
566 ms |
54688 KB |
Output is correct |
43 |
Correct |
105 ms |
9844 KB |
Output is correct |
44 |
Correct |
449 ms |
54784 KB |
Output is correct |
45 |
Correct |
304 ms |
54732 KB |
Output is correct |
46 |
Correct |
242 ms |
54804 KB |
Output is correct |
47 |
Correct |
196 ms |
52944 KB |
Output is correct |
48 |
Correct |
203 ms |
52624 KB |
Output is correct |
49 |
Correct |
226 ms |
53448 KB |
Output is correct |
50 |
Correct |
409 ms |
54184 KB |
Output is correct |
51 |
Correct |
205 ms |
53300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1858 ms |
193960 KB |
Output is correct |
2 |
Correct |
1189 ms |
196424 KB |
Output is correct |
3 |
Correct |
1395 ms |
176656 KB |
Output is correct |
4 |
Correct |
1784 ms |
190564 KB |
Output is correct |
5 |
Correct |
940 ms |
195768 KB |
Output is correct |
6 |
Correct |
1032 ms |
196328 KB |
Output is correct |
7 |
Correct |
1382 ms |
176980 KB |
Output is correct |
8 |
Correct |
1884 ms |
190240 KB |
Output is correct |
9 |
Correct |
1887 ms |
196028 KB |
Output is correct |
10 |
Correct |
1702 ms |
197812 KB |
Output is correct |
11 |
Correct |
1040 ms |
193876 KB |
Output is correct |
12 |
Correct |
1343 ms |
196952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2054 ms |
197608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
720 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
3462 ms |
58548 KB |
Output is correct |
32 |
Correct |
47 ms |
9536 KB |
Output is correct |
33 |
Correct |
469 ms |
55892 KB |
Output is correct |
34 |
Correct |
2590 ms |
56180 KB |
Output is correct |
35 |
Correct |
1638 ms |
58376 KB |
Output is correct |
36 |
Correct |
513 ms |
58244 KB |
Output is correct |
37 |
Correct |
397 ms |
54896 KB |
Output is correct |
38 |
Correct |
330 ms |
54860 KB |
Output is correct |
39 |
Correct |
278 ms |
54496 KB |
Output is correct |
40 |
Correct |
314 ms |
54584 KB |
Output is correct |
41 |
Correct |
486 ms |
54616 KB |
Output is correct |
42 |
Correct |
566 ms |
54688 KB |
Output is correct |
43 |
Correct |
105 ms |
9844 KB |
Output is correct |
44 |
Correct |
449 ms |
54784 KB |
Output is correct |
45 |
Correct |
304 ms |
54732 KB |
Output is correct |
46 |
Correct |
242 ms |
54804 KB |
Output is correct |
47 |
Correct |
196 ms |
52944 KB |
Output is correct |
48 |
Correct |
203 ms |
52624 KB |
Output is correct |
49 |
Correct |
226 ms |
53448 KB |
Output is correct |
50 |
Correct |
409 ms |
54184 KB |
Output is correct |
51 |
Correct |
205 ms |
53300 KB |
Output is correct |
52 |
Incorrect |
225 ms |
37056 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
720 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
3462 ms |
58548 KB |
Output is correct |
32 |
Correct |
47 ms |
9536 KB |
Output is correct |
33 |
Correct |
469 ms |
55892 KB |
Output is correct |
34 |
Correct |
2590 ms |
56180 KB |
Output is correct |
35 |
Correct |
1638 ms |
58376 KB |
Output is correct |
36 |
Correct |
513 ms |
58244 KB |
Output is correct |
37 |
Correct |
397 ms |
54896 KB |
Output is correct |
38 |
Correct |
330 ms |
54860 KB |
Output is correct |
39 |
Correct |
278 ms |
54496 KB |
Output is correct |
40 |
Correct |
314 ms |
54584 KB |
Output is correct |
41 |
Correct |
486 ms |
54616 KB |
Output is correct |
42 |
Correct |
566 ms |
54688 KB |
Output is correct |
43 |
Correct |
105 ms |
9844 KB |
Output is correct |
44 |
Correct |
449 ms |
54784 KB |
Output is correct |
45 |
Correct |
304 ms |
54732 KB |
Output is correct |
46 |
Correct |
242 ms |
54804 KB |
Output is correct |
47 |
Correct |
196 ms |
52944 KB |
Output is correct |
48 |
Correct |
203 ms |
52624 KB |
Output is correct |
49 |
Correct |
226 ms |
53448 KB |
Output is correct |
50 |
Correct |
409 ms |
54184 KB |
Output is correct |
51 |
Correct |
205 ms |
53300 KB |
Output is correct |
52 |
Correct |
1858 ms |
193960 KB |
Output is correct |
53 |
Correct |
1189 ms |
196424 KB |
Output is correct |
54 |
Correct |
1395 ms |
176656 KB |
Output is correct |
55 |
Correct |
1784 ms |
190564 KB |
Output is correct |
56 |
Correct |
940 ms |
195768 KB |
Output is correct |
57 |
Correct |
1032 ms |
196328 KB |
Output is correct |
58 |
Correct |
1382 ms |
176980 KB |
Output is correct |
59 |
Correct |
1884 ms |
190240 KB |
Output is correct |
60 |
Correct |
1887 ms |
196028 KB |
Output is correct |
61 |
Correct |
1702 ms |
197812 KB |
Output is correct |
62 |
Correct |
1040 ms |
193876 KB |
Output is correct |
63 |
Correct |
1343 ms |
196952 KB |
Output is correct |
64 |
Incorrect |
2054 ms |
197608 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |