#include <bits/stdc++.h>
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: In member function 'void DS::add(Pair)':
new_home.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j = idx; j < sp[i].size(); j += j & -j){
| ~~^~~~~~~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:137:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for(int i = 0; i < sp.size(); i++){
| ~~^~~~~~~~~~~
new_home.cpp: In lambda function:
new_home.cpp:179:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
179 | return a.t < b.t || a.t == b.t && a.ty < b.ty;
| ~~~~~~~~~~~^~~~~~~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:182:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
182 | for(int i = 0; i < Q.size(); i++){
| ~~^~~~~~~~~~
new_home.cpp:209:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
209 | for(int i = 0; i < Q.size(); i++){
| ~~^~~~~~~~~~
new_home.cpp:215:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
215 | for(int i = 0; i < Q.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
89532 KB |
Output is correct |
2 |
Correct |
66 ms |
89504 KB |
Output is correct |
3 |
Correct |
63 ms |
89592 KB |
Output is correct |
4 |
Correct |
67 ms |
89600 KB |
Output is correct |
5 |
Correct |
73 ms |
89932 KB |
Output is correct |
6 |
Correct |
71 ms |
89804 KB |
Output is correct |
7 |
Correct |
73 ms |
89640 KB |
Output is correct |
8 |
Correct |
74 ms |
89760 KB |
Output is correct |
9 |
Correct |
67 ms |
89624 KB |
Output is correct |
10 |
Correct |
81 ms |
89916 KB |
Output is correct |
11 |
Correct |
70 ms |
89744 KB |
Output is correct |
12 |
Correct |
79 ms |
89744 KB |
Output is correct |
13 |
Correct |
70 ms |
89680 KB |
Output is correct |
14 |
Correct |
71 ms |
89688 KB |
Output is correct |
15 |
Correct |
71 ms |
89684 KB |
Output is correct |
16 |
Correct |
73 ms |
89648 KB |
Output is correct |
17 |
Correct |
77 ms |
89692 KB |
Output is correct |
18 |
Correct |
75 ms |
89760 KB |
Output is correct |
19 |
Correct |
69 ms |
89804 KB |
Output is correct |
20 |
Correct |
69 ms |
89692 KB |
Output is correct |
21 |
Correct |
64 ms |
89552 KB |
Output is correct |
22 |
Correct |
83 ms |
89760 KB |
Output is correct |
23 |
Correct |
72 ms |
89676 KB |
Output is correct |
24 |
Correct |
68 ms |
89724 KB |
Output is correct |
25 |
Correct |
71 ms |
89720 KB |
Output is correct |
26 |
Correct |
80 ms |
89788 KB |
Output is correct |
27 |
Correct |
69 ms |
89668 KB |
Output is correct |
28 |
Correct |
76 ms |
89848 KB |
Output is correct |
29 |
Correct |
73 ms |
89708 KB |
Output is correct |
30 |
Correct |
68 ms |
89644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
89532 KB |
Output is correct |
2 |
Correct |
66 ms |
89504 KB |
Output is correct |
3 |
Correct |
63 ms |
89592 KB |
Output is correct |
4 |
Correct |
67 ms |
89600 KB |
Output is correct |
5 |
Correct |
73 ms |
89932 KB |
Output is correct |
6 |
Correct |
71 ms |
89804 KB |
Output is correct |
7 |
Correct |
73 ms |
89640 KB |
Output is correct |
8 |
Correct |
74 ms |
89760 KB |
Output is correct |
9 |
Correct |
67 ms |
89624 KB |
Output is correct |
10 |
Correct |
81 ms |
89916 KB |
Output is correct |
11 |
Correct |
70 ms |
89744 KB |
Output is correct |
12 |
Correct |
79 ms |
89744 KB |
Output is correct |
13 |
Correct |
70 ms |
89680 KB |
Output is correct |
14 |
Correct |
71 ms |
89688 KB |
Output is correct |
15 |
Correct |
71 ms |
89684 KB |
Output is correct |
16 |
Correct |
73 ms |
89648 KB |
Output is correct |
17 |
Correct |
77 ms |
89692 KB |
Output is correct |
18 |
Correct |
75 ms |
89760 KB |
Output is correct |
19 |
Correct |
69 ms |
89804 KB |
Output is correct |
20 |
Correct |
69 ms |
89692 KB |
Output is correct |
21 |
Correct |
64 ms |
89552 KB |
Output is correct |
22 |
Correct |
83 ms |
89760 KB |
Output is correct |
23 |
Correct |
72 ms |
89676 KB |
Output is correct |
24 |
Correct |
68 ms |
89724 KB |
Output is correct |
25 |
Correct |
71 ms |
89720 KB |
Output is correct |
26 |
Correct |
80 ms |
89788 KB |
Output is correct |
27 |
Correct |
69 ms |
89668 KB |
Output is correct |
28 |
Correct |
76 ms |
89848 KB |
Output is correct |
29 |
Correct |
73 ms |
89708 KB |
Output is correct |
30 |
Correct |
68 ms |
89644 KB |
Output is correct |
31 |
Correct |
4334 ms |
128384 KB |
Output is correct |
32 |
Correct |
686 ms |
135352 KB |
Output is correct |
33 |
Correct |
4368 ms |
130732 KB |
Output is correct |
34 |
Correct |
4325 ms |
130456 KB |
Output is correct |
35 |
Correct |
4959 ms |
131728 KB |
Output is correct |
36 |
Correct |
4389 ms |
131336 KB |
Output is correct |
37 |
Correct |
3901 ms |
130160 KB |
Output is correct |
38 |
Correct |
3357 ms |
129832 KB |
Output is correct |
39 |
Correct |
3172 ms |
129024 KB |
Output is correct |
40 |
Correct |
3075 ms |
129392 KB |
Output is correct |
41 |
Correct |
1908 ms |
117316 KB |
Output is correct |
42 |
Correct |
1336 ms |
117080 KB |
Output is correct |
43 |
Correct |
270 ms |
114256 KB |
Output is correct |
44 |
Correct |
1874 ms |
117380 KB |
Output is correct |
45 |
Correct |
2052 ms |
117328 KB |
Output is correct |
46 |
Correct |
2461 ms |
117228 KB |
Output is correct |
47 |
Correct |
1336 ms |
112324 KB |
Output is correct |
48 |
Correct |
1674 ms |
113452 KB |
Output is correct |
49 |
Correct |
1780 ms |
114816 KB |
Output is correct |
50 |
Correct |
1549 ms |
114268 KB |
Output is correct |
51 |
Correct |
2183 ms |
115352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2224 ms |
398928 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3175 ms |
459472 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
89532 KB |
Output is correct |
2 |
Correct |
66 ms |
89504 KB |
Output is correct |
3 |
Correct |
63 ms |
89592 KB |
Output is correct |
4 |
Correct |
67 ms |
89600 KB |
Output is correct |
5 |
Correct |
73 ms |
89932 KB |
Output is correct |
6 |
Correct |
71 ms |
89804 KB |
Output is correct |
7 |
Correct |
73 ms |
89640 KB |
Output is correct |
8 |
Correct |
74 ms |
89760 KB |
Output is correct |
9 |
Correct |
67 ms |
89624 KB |
Output is correct |
10 |
Correct |
81 ms |
89916 KB |
Output is correct |
11 |
Correct |
70 ms |
89744 KB |
Output is correct |
12 |
Correct |
79 ms |
89744 KB |
Output is correct |
13 |
Correct |
70 ms |
89680 KB |
Output is correct |
14 |
Correct |
71 ms |
89688 KB |
Output is correct |
15 |
Correct |
71 ms |
89684 KB |
Output is correct |
16 |
Correct |
73 ms |
89648 KB |
Output is correct |
17 |
Correct |
77 ms |
89692 KB |
Output is correct |
18 |
Correct |
75 ms |
89760 KB |
Output is correct |
19 |
Correct |
69 ms |
89804 KB |
Output is correct |
20 |
Correct |
69 ms |
89692 KB |
Output is correct |
21 |
Correct |
64 ms |
89552 KB |
Output is correct |
22 |
Correct |
83 ms |
89760 KB |
Output is correct |
23 |
Correct |
72 ms |
89676 KB |
Output is correct |
24 |
Correct |
68 ms |
89724 KB |
Output is correct |
25 |
Correct |
71 ms |
89720 KB |
Output is correct |
26 |
Correct |
80 ms |
89788 KB |
Output is correct |
27 |
Correct |
69 ms |
89668 KB |
Output is correct |
28 |
Correct |
76 ms |
89848 KB |
Output is correct |
29 |
Correct |
73 ms |
89708 KB |
Output is correct |
30 |
Correct |
68 ms |
89644 KB |
Output is correct |
31 |
Correct |
4334 ms |
128384 KB |
Output is correct |
32 |
Correct |
686 ms |
135352 KB |
Output is correct |
33 |
Correct |
4368 ms |
130732 KB |
Output is correct |
34 |
Correct |
4325 ms |
130456 KB |
Output is correct |
35 |
Correct |
4959 ms |
131728 KB |
Output is correct |
36 |
Correct |
4389 ms |
131336 KB |
Output is correct |
37 |
Correct |
3901 ms |
130160 KB |
Output is correct |
38 |
Correct |
3357 ms |
129832 KB |
Output is correct |
39 |
Correct |
3172 ms |
129024 KB |
Output is correct |
40 |
Correct |
3075 ms |
129392 KB |
Output is correct |
41 |
Correct |
1908 ms |
117316 KB |
Output is correct |
42 |
Correct |
1336 ms |
117080 KB |
Output is correct |
43 |
Correct |
270 ms |
114256 KB |
Output is correct |
44 |
Correct |
1874 ms |
117380 KB |
Output is correct |
45 |
Correct |
2052 ms |
117328 KB |
Output is correct |
46 |
Correct |
2461 ms |
117228 KB |
Output is correct |
47 |
Correct |
1336 ms |
112324 KB |
Output is correct |
48 |
Correct |
1674 ms |
113452 KB |
Output is correct |
49 |
Correct |
1780 ms |
114816 KB |
Output is correct |
50 |
Correct |
1549 ms |
114268 KB |
Output is correct |
51 |
Correct |
2183 ms |
115352 KB |
Output is correct |
52 |
Correct |
574 ms |
103080 KB |
Output is correct |
53 |
Correct |
510 ms |
102340 KB |
Output is correct |
54 |
Correct |
1144 ms |
113844 KB |
Output is correct |
55 |
Correct |
1493 ms |
112256 KB |
Output is correct |
56 |
Correct |
1370 ms |
110236 KB |
Output is correct |
57 |
Correct |
1698 ms |
116152 KB |
Output is correct |
58 |
Correct |
1326 ms |
112164 KB |
Output is correct |
59 |
Correct |
1106 ms |
109756 KB |
Output is correct |
60 |
Correct |
1459 ms |
115944 KB |
Output is correct |
61 |
Correct |
169 ms |
101760 KB |
Output is correct |
62 |
Correct |
512 ms |
103012 KB |
Output is correct |
63 |
Correct |
978 ms |
108996 KB |
Output is correct |
64 |
Correct |
1147 ms |
111556 KB |
Output is correct |
65 |
Correct |
1417 ms |
115304 KB |
Output is correct |
66 |
Correct |
1653 ms |
117352 KB |
Output is correct |
67 |
Correct |
422 ms |
116392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
89532 KB |
Output is correct |
2 |
Correct |
66 ms |
89504 KB |
Output is correct |
3 |
Correct |
63 ms |
89592 KB |
Output is correct |
4 |
Correct |
67 ms |
89600 KB |
Output is correct |
5 |
Correct |
73 ms |
89932 KB |
Output is correct |
6 |
Correct |
71 ms |
89804 KB |
Output is correct |
7 |
Correct |
73 ms |
89640 KB |
Output is correct |
8 |
Correct |
74 ms |
89760 KB |
Output is correct |
9 |
Correct |
67 ms |
89624 KB |
Output is correct |
10 |
Correct |
81 ms |
89916 KB |
Output is correct |
11 |
Correct |
70 ms |
89744 KB |
Output is correct |
12 |
Correct |
79 ms |
89744 KB |
Output is correct |
13 |
Correct |
70 ms |
89680 KB |
Output is correct |
14 |
Correct |
71 ms |
89688 KB |
Output is correct |
15 |
Correct |
71 ms |
89684 KB |
Output is correct |
16 |
Correct |
73 ms |
89648 KB |
Output is correct |
17 |
Correct |
77 ms |
89692 KB |
Output is correct |
18 |
Correct |
75 ms |
89760 KB |
Output is correct |
19 |
Correct |
69 ms |
89804 KB |
Output is correct |
20 |
Correct |
69 ms |
89692 KB |
Output is correct |
21 |
Correct |
64 ms |
89552 KB |
Output is correct |
22 |
Correct |
83 ms |
89760 KB |
Output is correct |
23 |
Correct |
72 ms |
89676 KB |
Output is correct |
24 |
Correct |
68 ms |
89724 KB |
Output is correct |
25 |
Correct |
71 ms |
89720 KB |
Output is correct |
26 |
Correct |
80 ms |
89788 KB |
Output is correct |
27 |
Correct |
69 ms |
89668 KB |
Output is correct |
28 |
Correct |
76 ms |
89848 KB |
Output is correct |
29 |
Correct |
73 ms |
89708 KB |
Output is correct |
30 |
Correct |
68 ms |
89644 KB |
Output is correct |
31 |
Correct |
4334 ms |
128384 KB |
Output is correct |
32 |
Correct |
686 ms |
135352 KB |
Output is correct |
33 |
Correct |
4368 ms |
130732 KB |
Output is correct |
34 |
Correct |
4325 ms |
130456 KB |
Output is correct |
35 |
Correct |
4959 ms |
131728 KB |
Output is correct |
36 |
Correct |
4389 ms |
131336 KB |
Output is correct |
37 |
Correct |
3901 ms |
130160 KB |
Output is correct |
38 |
Correct |
3357 ms |
129832 KB |
Output is correct |
39 |
Correct |
3172 ms |
129024 KB |
Output is correct |
40 |
Correct |
3075 ms |
129392 KB |
Output is correct |
41 |
Correct |
1908 ms |
117316 KB |
Output is correct |
42 |
Correct |
1336 ms |
117080 KB |
Output is correct |
43 |
Correct |
270 ms |
114256 KB |
Output is correct |
44 |
Correct |
1874 ms |
117380 KB |
Output is correct |
45 |
Correct |
2052 ms |
117328 KB |
Output is correct |
46 |
Correct |
2461 ms |
117228 KB |
Output is correct |
47 |
Correct |
1336 ms |
112324 KB |
Output is correct |
48 |
Correct |
1674 ms |
113452 KB |
Output is correct |
49 |
Correct |
1780 ms |
114816 KB |
Output is correct |
50 |
Correct |
1549 ms |
114268 KB |
Output is correct |
51 |
Correct |
2183 ms |
115352 KB |
Output is correct |
52 |
Runtime error |
2224 ms |
398928 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |