#include <bits/stdc++.h>
#pragma optimize("unroll-loops")
#pragma optimize("Ofast")
const int N = 300013;
using namespace std;
struct Store{
int x, ty, a, b;
};
struct Query{
int t, ty, x, id;
};
struct Pair{
Pair() = default;
Pair(int _x, int _y, int _d) : x(_x), y(_y), d(_d){};
int x, y, d;
};
struct DS{
vector<int> sp[N], bits[N];
string name;
DS() = default;
DS(string _n) : name(_n){}
void insert(Pair p){
int x = p.x + 1, y = p.y + 1;
for(int i = x; i < N; i += i & -i){
sp[i].push_back(y);
}
}
void parse(){
for(int i = 0; i < N; i++) sp[i].push_back(0);
for(int i = 0; i < N; i++){
sort(sp[i].begin(), sp[i].end());
sp[i].resize(unique(sp[i].begin(), sp[i].end()) - sp[i].begin());
bits[i].resize(sp[i].size());
}
}
void add(Pair p){
int x = p.x + 1, y = p.y + 1;
for(int i = x; i < N; i += i & -i){
int idx = lower_bound(sp[i].begin(), sp[i].end(), y) - sp[i].begin();
for(int j = idx; j < sp[i].size(); j += j & -j){
bits[i][j] += p.d;
}
}
}
int qry(int x, int y){
x++; y++;
int ret = 0;
for(int i = x; i; i -= i & -i){
int idx = upper_bound(sp[i].begin(), sp[i].end(), y) - 1 - sp[i].begin();
for(int j = idx; j; j -= j & -j){
ret += bits[i][j];
}
}
return ret;
}
int qry(int x1, int x2, int y1, int y2){
return qry(x2, y2) + qry(x1 - 1, y1 - 1) - qry(x2, y1 - 1) - qry(x1 - 1, y2);
}
} ds;
struct BIT{
int bit[N];
void add(int p, int v){
p++;
for(int i = p; i < N; i += i & -i){
bit[i] += v;
}
}
int qry(int p){
int ret = 0;
p++;
for(int i = p; i; i -= i & -i){
ret += bit[i];
}
return ret;
}
int qry(int l, int r){
return qry(r) - qry(l - 1);
}
} bit;
vector<Store> stores;
vector<Query> Q;
vector<Pair> C[N * 3], D[N * 3];
int m;
int p[N * 2];
int ans[N];
int n, k, q;
bool check(int x1, int x2){
int l = lower_bound(p, p + m, x1) - p;
int r = upper_bound(p, p + m, x2) - 1 - p;
int c1 = bit.qry(l, r);
int c2 = ds.qry(l, r, l, r);
assert(c1 - c2 >= 0 && c1 - c2 <= k);
return c1 - c2 == k;
}
int qry(int x){
int l = 0, r = 1e9;
while(l != r){
int mid = (l + r) / 2;
if(check(p[x] - mid, p[x] + mid)){
r = mid;
}else{
l = mid + 1;
}
}
return l >= 9e8 ? -1 : l;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k >> q;
vector<int> sp;
for(int i = 0; i < n; i++){
int x, ty, a, b;
cin >> x >> ty >> a >> b;
stores.push_back({x, ty, a, b + 1});
sp.push_back(a);
sp.push_back(b + 1);
}
for(int i = 0; i < q; i++){
int x, t;
cin >> x >> t;
Q.push_back({t, 2, x, i});
}
sort(sp.begin(), sp.end());
sp.resize(unique(sp.begin(), sp.end()) - sp.begin());
{
map<int, int> M;
for(int i = 0; i < sp.size(); i++){
M[sp[i]] = i;
}
for(auto& st : stores){
st.a = M[st.a];
st.b = M[st.b];
}
for(auto& q : Q){
q.t = upper_bound(sp.begin(), sp.end(), q.t) - sp.begin() - 1;
}
}
{
vector<int> xs;
for(auto st : stores){
xs.push_back(st.x);
}
for(auto q : Q){
xs.push_back(q.x);
}
sort(xs.begin(), xs.end());
xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
m = xs.size();
for(int i = 0; i < m; i++){
p[i] = xs[i];
}
map<int, int> M;
for(int i = 0; i < m; i++){
M[xs[i]] = i;
}
for(auto& st : stores){
st.x = M[st.x];
}
for(auto& q : Q){
q.x = M[q.x];
}
}
for(auto st : stores){
Q.push_back({st.a, 1, st.x, st.ty});
Q.push_back({st.b, 0, st.x, st.ty});
}
sort(Q.begin(), Q.end(), [](Query a, Query b){
return a.t < b.t || a.t == b.t && a.ty < b.ty;
});
multiset<int> vset[N];
for(int i = 0; i < Q.size(); i++){
Query q = Q[i];
auto ptr = vset[q.id].begin();
switch(q.ty){
case 0:
ptr = vset[q.id].lower_bound(q.x);
assert(ptr != vset[q.id].end());
if(ptr != vset[q.id].begin()) C[i].push_back({*prev(ptr), *ptr, -1});
if(next(ptr) != vset[q.id].end()) C[i].push_back({*ptr, *next(ptr), -1});
if(ptr != vset[q.id].begin() && next(ptr) != vset[q.id].end()) C[i].push_back({*prev(ptr), *next(ptr), 1});
D[i].push_back({q.x, -1, -1});
vset[q.id].erase(ptr);
break;
case 1:
ptr = vset[q.id].lower_bound(q.x);
if(ptr != vset[q.id].end() && ptr != vset[q.id].begin()) C[i].push_back({*prev(ptr), *ptr, -1});
if(ptr != vset[q.id].end()) C[i].push_back({q.x, *ptr, 1});
if(ptr != vset[q.id].begin()) C[i].push_back({*prev(ptr), q.x, 1});
D[i].push_back({q.x, -1, 1});
vset[q.id].insert(q.x);
break;
case 2:
break;
default:
assert(false);
}
}
for(int i = 0; i < Q.size(); i++){
for(auto p : C[i]){
ds.insert(p);
}
}
ds.parse();
for(int i = 0; i < Q.size(); i++){
for(auto p : C[i]){
ds.add(p);
}
for(auto p : D[i]){
bit.add(p.x, p.d);
}
Query q = Q[i];
switch(q.ty){
case 0:
break;
case 1:
break;
case 2: ans[q.id] = qry(q.x); break;
default: assert(false);
}
}
for(int i = 0; i < q; i++){
cout << ans[i] << '\n';
}
}
Compilation message
new_home.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize("unroll-loops")
|
new_home.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("Ofast")
|
new_home.cpp: In member function 'void DS::add(Pair)':
new_home.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = idx; j < sp[i].size(); j += j & -j){
| ~~^~~~~~~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:138:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
138 | for(int i = 0; i < sp.size(); i++){
| ~~^~~~~~~~~~~
new_home.cpp: In lambda function:
new_home.cpp:180:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
180 | return a.t < b.t || a.t == b.t && a.ty < b.ty;
| ~~~~~~~~~~~^~~~~~~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:183:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
183 | for(int i = 0; i < Q.size(); i++){
| ~~^~~~~~~~~~
new_home.cpp:210:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
210 | for(int i = 0; i < Q.size(); i++){
| ~~^~~~~~~~~~
new_home.cpp:216:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
216 | for(int i = 0; i < Q.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
89492 KB |
Output is correct |
2 |
Correct |
64 ms |
89596 KB |
Output is correct |
3 |
Correct |
64 ms |
89596 KB |
Output is correct |
4 |
Correct |
69 ms |
89584 KB |
Output is correct |
5 |
Correct |
75 ms |
89920 KB |
Output is correct |
6 |
Correct |
75 ms |
89848 KB |
Output is correct |
7 |
Correct |
64 ms |
89564 KB |
Output is correct |
8 |
Correct |
70 ms |
89720 KB |
Output is correct |
9 |
Correct |
66 ms |
89620 KB |
Output is correct |
10 |
Correct |
79 ms |
89840 KB |
Output is correct |
11 |
Correct |
69 ms |
89732 KB |
Output is correct |
12 |
Correct |
73 ms |
89828 KB |
Output is correct |
13 |
Correct |
70 ms |
89716 KB |
Output is correct |
14 |
Correct |
69 ms |
89648 KB |
Output is correct |
15 |
Correct |
69 ms |
89672 KB |
Output is correct |
16 |
Correct |
82 ms |
89680 KB |
Output is correct |
17 |
Correct |
76 ms |
89788 KB |
Output is correct |
18 |
Correct |
69 ms |
89676 KB |
Output is correct |
19 |
Correct |
71 ms |
89632 KB |
Output is correct |
20 |
Correct |
71 ms |
89780 KB |
Output is correct |
21 |
Correct |
65 ms |
89628 KB |
Output is correct |
22 |
Correct |
67 ms |
89612 KB |
Output is correct |
23 |
Correct |
67 ms |
89644 KB |
Output is correct |
24 |
Correct |
69 ms |
89668 KB |
Output is correct |
25 |
Correct |
68 ms |
89724 KB |
Output is correct |
26 |
Correct |
72 ms |
89812 KB |
Output is correct |
27 |
Correct |
67 ms |
89804 KB |
Output is correct |
28 |
Correct |
68 ms |
89700 KB |
Output is correct |
29 |
Correct |
72 ms |
89768 KB |
Output is correct |
30 |
Correct |
72 ms |
89780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
89492 KB |
Output is correct |
2 |
Correct |
64 ms |
89596 KB |
Output is correct |
3 |
Correct |
64 ms |
89596 KB |
Output is correct |
4 |
Correct |
69 ms |
89584 KB |
Output is correct |
5 |
Correct |
75 ms |
89920 KB |
Output is correct |
6 |
Correct |
75 ms |
89848 KB |
Output is correct |
7 |
Correct |
64 ms |
89564 KB |
Output is correct |
8 |
Correct |
70 ms |
89720 KB |
Output is correct |
9 |
Correct |
66 ms |
89620 KB |
Output is correct |
10 |
Correct |
79 ms |
89840 KB |
Output is correct |
11 |
Correct |
69 ms |
89732 KB |
Output is correct |
12 |
Correct |
73 ms |
89828 KB |
Output is correct |
13 |
Correct |
70 ms |
89716 KB |
Output is correct |
14 |
Correct |
69 ms |
89648 KB |
Output is correct |
15 |
Correct |
69 ms |
89672 KB |
Output is correct |
16 |
Correct |
82 ms |
89680 KB |
Output is correct |
17 |
Correct |
76 ms |
89788 KB |
Output is correct |
18 |
Correct |
69 ms |
89676 KB |
Output is correct |
19 |
Correct |
71 ms |
89632 KB |
Output is correct |
20 |
Correct |
71 ms |
89780 KB |
Output is correct |
21 |
Correct |
65 ms |
89628 KB |
Output is correct |
22 |
Correct |
67 ms |
89612 KB |
Output is correct |
23 |
Correct |
67 ms |
89644 KB |
Output is correct |
24 |
Correct |
69 ms |
89668 KB |
Output is correct |
25 |
Correct |
68 ms |
89724 KB |
Output is correct |
26 |
Correct |
72 ms |
89812 KB |
Output is correct |
27 |
Correct |
67 ms |
89804 KB |
Output is correct |
28 |
Correct |
68 ms |
89700 KB |
Output is correct |
29 |
Correct |
72 ms |
89768 KB |
Output is correct |
30 |
Correct |
72 ms |
89780 KB |
Output is correct |
31 |
Correct |
4339 ms |
128632 KB |
Output is correct |
32 |
Correct |
553 ms |
135484 KB |
Output is correct |
33 |
Correct |
4009 ms |
130732 KB |
Output is correct |
34 |
Correct |
4046 ms |
130388 KB |
Output is correct |
35 |
Correct |
4412 ms |
131760 KB |
Output is correct |
36 |
Correct |
4074 ms |
131220 KB |
Output is correct |
37 |
Correct |
3497 ms |
130156 KB |
Output is correct |
38 |
Correct |
3246 ms |
130060 KB |
Output is correct |
39 |
Correct |
2729 ms |
129044 KB |
Output is correct |
40 |
Correct |
2847 ms |
129516 KB |
Output is correct |
41 |
Correct |
1672 ms |
117248 KB |
Output is correct |
42 |
Correct |
1289 ms |
117112 KB |
Output is correct |
43 |
Correct |
250 ms |
114224 KB |
Output is correct |
44 |
Correct |
1670 ms |
117424 KB |
Output is correct |
45 |
Correct |
1912 ms |
117300 KB |
Output is correct |
46 |
Correct |
2391 ms |
117224 KB |
Output is correct |
47 |
Correct |
1288 ms |
112324 KB |
Output is correct |
48 |
Correct |
1573 ms |
113504 KB |
Output is correct |
49 |
Correct |
1738 ms |
115240 KB |
Output is correct |
50 |
Correct |
1508 ms |
114416 KB |
Output is correct |
51 |
Correct |
2059 ms |
115452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2121 ms |
399120 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3088 ms |
459868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
89492 KB |
Output is correct |
2 |
Correct |
64 ms |
89596 KB |
Output is correct |
3 |
Correct |
64 ms |
89596 KB |
Output is correct |
4 |
Correct |
69 ms |
89584 KB |
Output is correct |
5 |
Correct |
75 ms |
89920 KB |
Output is correct |
6 |
Correct |
75 ms |
89848 KB |
Output is correct |
7 |
Correct |
64 ms |
89564 KB |
Output is correct |
8 |
Correct |
70 ms |
89720 KB |
Output is correct |
9 |
Correct |
66 ms |
89620 KB |
Output is correct |
10 |
Correct |
79 ms |
89840 KB |
Output is correct |
11 |
Correct |
69 ms |
89732 KB |
Output is correct |
12 |
Correct |
73 ms |
89828 KB |
Output is correct |
13 |
Correct |
70 ms |
89716 KB |
Output is correct |
14 |
Correct |
69 ms |
89648 KB |
Output is correct |
15 |
Correct |
69 ms |
89672 KB |
Output is correct |
16 |
Correct |
82 ms |
89680 KB |
Output is correct |
17 |
Correct |
76 ms |
89788 KB |
Output is correct |
18 |
Correct |
69 ms |
89676 KB |
Output is correct |
19 |
Correct |
71 ms |
89632 KB |
Output is correct |
20 |
Correct |
71 ms |
89780 KB |
Output is correct |
21 |
Correct |
65 ms |
89628 KB |
Output is correct |
22 |
Correct |
67 ms |
89612 KB |
Output is correct |
23 |
Correct |
67 ms |
89644 KB |
Output is correct |
24 |
Correct |
69 ms |
89668 KB |
Output is correct |
25 |
Correct |
68 ms |
89724 KB |
Output is correct |
26 |
Correct |
72 ms |
89812 KB |
Output is correct |
27 |
Correct |
67 ms |
89804 KB |
Output is correct |
28 |
Correct |
68 ms |
89700 KB |
Output is correct |
29 |
Correct |
72 ms |
89768 KB |
Output is correct |
30 |
Correct |
72 ms |
89780 KB |
Output is correct |
31 |
Correct |
4339 ms |
128632 KB |
Output is correct |
32 |
Correct |
553 ms |
135484 KB |
Output is correct |
33 |
Correct |
4009 ms |
130732 KB |
Output is correct |
34 |
Correct |
4046 ms |
130388 KB |
Output is correct |
35 |
Correct |
4412 ms |
131760 KB |
Output is correct |
36 |
Correct |
4074 ms |
131220 KB |
Output is correct |
37 |
Correct |
3497 ms |
130156 KB |
Output is correct |
38 |
Correct |
3246 ms |
130060 KB |
Output is correct |
39 |
Correct |
2729 ms |
129044 KB |
Output is correct |
40 |
Correct |
2847 ms |
129516 KB |
Output is correct |
41 |
Correct |
1672 ms |
117248 KB |
Output is correct |
42 |
Correct |
1289 ms |
117112 KB |
Output is correct |
43 |
Correct |
250 ms |
114224 KB |
Output is correct |
44 |
Correct |
1670 ms |
117424 KB |
Output is correct |
45 |
Correct |
1912 ms |
117300 KB |
Output is correct |
46 |
Correct |
2391 ms |
117224 KB |
Output is correct |
47 |
Correct |
1288 ms |
112324 KB |
Output is correct |
48 |
Correct |
1573 ms |
113504 KB |
Output is correct |
49 |
Correct |
1738 ms |
115240 KB |
Output is correct |
50 |
Correct |
1508 ms |
114416 KB |
Output is correct |
51 |
Correct |
2059 ms |
115452 KB |
Output is correct |
52 |
Correct |
519 ms |
102892 KB |
Output is correct |
53 |
Correct |
508 ms |
102296 KB |
Output is correct |
54 |
Correct |
1080 ms |
113764 KB |
Output is correct |
55 |
Correct |
1451 ms |
112216 KB |
Output is correct |
56 |
Correct |
1349 ms |
110072 KB |
Output is correct |
57 |
Correct |
1655 ms |
116004 KB |
Output is correct |
58 |
Correct |
1236 ms |
112156 KB |
Output is correct |
59 |
Correct |
1088 ms |
109748 KB |
Output is correct |
60 |
Correct |
1292 ms |
115820 KB |
Output is correct |
61 |
Correct |
164 ms |
101648 KB |
Output is correct |
62 |
Correct |
526 ms |
103056 KB |
Output is correct |
63 |
Correct |
969 ms |
109012 KB |
Output is correct |
64 |
Correct |
1061 ms |
111552 KB |
Output is correct |
65 |
Correct |
1350 ms |
115244 KB |
Output is correct |
66 |
Correct |
1553 ms |
117252 KB |
Output is correct |
67 |
Correct |
410 ms |
116332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
89492 KB |
Output is correct |
2 |
Correct |
64 ms |
89596 KB |
Output is correct |
3 |
Correct |
64 ms |
89596 KB |
Output is correct |
4 |
Correct |
69 ms |
89584 KB |
Output is correct |
5 |
Correct |
75 ms |
89920 KB |
Output is correct |
6 |
Correct |
75 ms |
89848 KB |
Output is correct |
7 |
Correct |
64 ms |
89564 KB |
Output is correct |
8 |
Correct |
70 ms |
89720 KB |
Output is correct |
9 |
Correct |
66 ms |
89620 KB |
Output is correct |
10 |
Correct |
79 ms |
89840 KB |
Output is correct |
11 |
Correct |
69 ms |
89732 KB |
Output is correct |
12 |
Correct |
73 ms |
89828 KB |
Output is correct |
13 |
Correct |
70 ms |
89716 KB |
Output is correct |
14 |
Correct |
69 ms |
89648 KB |
Output is correct |
15 |
Correct |
69 ms |
89672 KB |
Output is correct |
16 |
Correct |
82 ms |
89680 KB |
Output is correct |
17 |
Correct |
76 ms |
89788 KB |
Output is correct |
18 |
Correct |
69 ms |
89676 KB |
Output is correct |
19 |
Correct |
71 ms |
89632 KB |
Output is correct |
20 |
Correct |
71 ms |
89780 KB |
Output is correct |
21 |
Correct |
65 ms |
89628 KB |
Output is correct |
22 |
Correct |
67 ms |
89612 KB |
Output is correct |
23 |
Correct |
67 ms |
89644 KB |
Output is correct |
24 |
Correct |
69 ms |
89668 KB |
Output is correct |
25 |
Correct |
68 ms |
89724 KB |
Output is correct |
26 |
Correct |
72 ms |
89812 KB |
Output is correct |
27 |
Correct |
67 ms |
89804 KB |
Output is correct |
28 |
Correct |
68 ms |
89700 KB |
Output is correct |
29 |
Correct |
72 ms |
89768 KB |
Output is correct |
30 |
Correct |
72 ms |
89780 KB |
Output is correct |
31 |
Correct |
4339 ms |
128632 KB |
Output is correct |
32 |
Correct |
553 ms |
135484 KB |
Output is correct |
33 |
Correct |
4009 ms |
130732 KB |
Output is correct |
34 |
Correct |
4046 ms |
130388 KB |
Output is correct |
35 |
Correct |
4412 ms |
131760 KB |
Output is correct |
36 |
Correct |
4074 ms |
131220 KB |
Output is correct |
37 |
Correct |
3497 ms |
130156 KB |
Output is correct |
38 |
Correct |
3246 ms |
130060 KB |
Output is correct |
39 |
Correct |
2729 ms |
129044 KB |
Output is correct |
40 |
Correct |
2847 ms |
129516 KB |
Output is correct |
41 |
Correct |
1672 ms |
117248 KB |
Output is correct |
42 |
Correct |
1289 ms |
117112 KB |
Output is correct |
43 |
Correct |
250 ms |
114224 KB |
Output is correct |
44 |
Correct |
1670 ms |
117424 KB |
Output is correct |
45 |
Correct |
1912 ms |
117300 KB |
Output is correct |
46 |
Correct |
2391 ms |
117224 KB |
Output is correct |
47 |
Correct |
1288 ms |
112324 KB |
Output is correct |
48 |
Correct |
1573 ms |
113504 KB |
Output is correct |
49 |
Correct |
1738 ms |
115240 KB |
Output is correct |
50 |
Correct |
1508 ms |
114416 KB |
Output is correct |
51 |
Correct |
2059 ms |
115452 KB |
Output is correct |
52 |
Runtime error |
2121 ms |
399120 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |