#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define pd pair<double,double>
const int siz = 3e5 + 2;
multiset<int> col[siz];
int K;
struct node {
int l, r, mid, maxi;
bool p=0;
multiset<int> s;
node* sl = NULL;
node *sr = NULL;
node(int li, int ri) {
l = li, r = ri, mid = (l + r) / 2, maxi = 0;
if (l == 0) {
maxi = 3e8 + 1;
if (r == 0) {
for (int i = 0; i < K; i++)s.insert(3e8 + 1);
}
else open();
}
}
void open() {
if (sl == NULL && (l < r)) {
p = 1;
sl = new node(l, mid);
sr = new node(mid + 1, r);
}
}
int query(int a, int b) {
if (a > r || b < l)return 0;
if (a <= l && b >= r)return maxi;
if (p)return max(sl->query(a, b), sr->query(a, b));
return 0;
}
void update(int v, int x, bool f) {
if (l == r) {
if (f)s.insert(v);
else s.erase(s.find(v));
if (s.size())maxi = *(--s.end());
else maxi = 0;
}
else {
if (sl == NULL)open();
if (x <= mid) {
sl->update(v, x, f);
}
else {
sr->update(v, x, f);
}
maxi = max(sl->maxi, sr->maxi);
}
}
};
map<pi, int> sum;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, k, q;
cin >> n >> k >> q;
vector<vi> ev;
K = k;
for (int i = 0; i < n; i++) {
int x, t, a, b;
cin >> x >> t >> a >> b;
x++;
ev.push_back({ a,1,x,t });
ev.push_back({b+1,0,x,t });
}
for (int i = 0; i < siz; i++) {
col[i].insert(0);
col[i].insert(3e8 + 1);
}
for (int i = 0; i < q; i++) {
int l, y;
cin >> l >> y;
l++;
ev.push_back({ y,l,i });
}
sort(ev.begin(), ev.end());
node* seg = new node(0, 3e8 + 3);
vi ans(q);
for (vi v : ev) {
if (v.size() == 3) {
int l = v[1];
int a = 0, b = 1e8 + 3;
while (a < b) {
int mid = (a + b) / 2;
int ans = seg->query(0, max(l - mid - 1, 0));
if (ans <= mid + l) {
b = mid;
}
else {
a = mid+1;
}
}
if (b == 1e8 + 3)ans[v[2]] = -1;
else ans[v[2]] = b;
}
else {
int x = v[2], t = v[3];
if (v[1])sum[{x, t}]++;
else sum[{x,t}]--;
if (v[1] == sum[{x,t}]) {
auto it = col[t].lower_bound(x);
auto it1 = it, it2 = it;
it1--; if (v[1] == 0)it2++;
if (v[1] == 0)col[t].erase(x);
else col[t].insert(x);
seg->update(*it2, x, v[1]);
seg->update(*it2, *it1, !v[1]);
seg->update(x, *it1, v[1]);
}
}
}
for (int i = 0; i < q; i++)cout << ans[i] << "\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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
42580 KB |
Output is correct |
2 |
Correct |
32 ms |
42580 KB |
Output is correct |
3 |
Correct |
33 ms |
42576 KB |
Output is correct |
4 |
Correct |
34 ms |
42588 KB |
Output is correct |
5 |
Correct |
34 ms |
42684 KB |
Output is correct |
6 |
Correct |
36 ms |
44112 KB |
Output is correct |
7 |
Correct |
36 ms |
43980 KB |
Output is correct |
8 |
Correct |
36 ms |
44124 KB |
Output is correct |
9 |
Correct |
47 ms |
44028 KB |
Output is correct |
10 |
Correct |
36 ms |
43996 KB |
Output is correct |
11 |
Correct |
37 ms |
44116 KB |
Output is correct |
12 |
Correct |
35 ms |
44120 KB |
Output is correct |
13 |
Correct |
36 ms |
44120 KB |
Output is correct |
14 |
Correct |
37 ms |
43984 KB |
Output is correct |
15 |
Correct |
37 ms |
44024 KB |
Output is correct |
16 |
Correct |
37 ms |
44112 KB |
Output is correct |
17 |
Correct |
38 ms |
44252 KB |
Output is correct |
18 |
Correct |
40 ms |
44124 KB |
Output is correct |
19 |
Correct |
36 ms |
44116 KB |
Output is correct |
20 |
Correct |
38 ms |
44168 KB |
Output is correct |
21 |
Correct |
36 ms |
42832 KB |
Output is correct |
22 |
Correct |
37 ms |
44124 KB |
Output is correct |
23 |
Correct |
37 ms |
44112 KB |
Output is correct |
24 |
Correct |
36 ms |
44124 KB |
Output is correct |
25 |
Correct |
36 ms |
44124 KB |
Output is correct |
26 |
Correct |
37 ms |
44116 KB |
Output is correct |
27 |
Correct |
40 ms |
42832 KB |
Output is correct |
28 |
Correct |
36 ms |
44112 KB |
Output is correct |
29 |
Correct |
36 ms |
44116 KB |
Output is correct |
30 |
Correct |
36 ms |
43860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
42580 KB |
Output is correct |
2 |
Correct |
32 ms |
42580 KB |
Output is correct |
3 |
Correct |
33 ms |
42576 KB |
Output is correct |
4 |
Correct |
34 ms |
42588 KB |
Output is correct |
5 |
Correct |
34 ms |
42684 KB |
Output is correct |
6 |
Correct |
36 ms |
44112 KB |
Output is correct |
7 |
Correct |
36 ms |
43980 KB |
Output is correct |
8 |
Correct |
36 ms |
44124 KB |
Output is correct |
9 |
Correct |
47 ms |
44028 KB |
Output is correct |
10 |
Correct |
36 ms |
43996 KB |
Output is correct |
11 |
Correct |
37 ms |
44116 KB |
Output is correct |
12 |
Correct |
35 ms |
44120 KB |
Output is correct |
13 |
Correct |
36 ms |
44120 KB |
Output is correct |
14 |
Correct |
37 ms |
43984 KB |
Output is correct |
15 |
Correct |
37 ms |
44024 KB |
Output is correct |
16 |
Correct |
37 ms |
44112 KB |
Output is correct |
17 |
Correct |
38 ms |
44252 KB |
Output is correct |
18 |
Correct |
40 ms |
44124 KB |
Output is correct |
19 |
Correct |
36 ms |
44116 KB |
Output is correct |
20 |
Correct |
38 ms |
44168 KB |
Output is correct |
21 |
Correct |
36 ms |
42832 KB |
Output is correct |
22 |
Correct |
37 ms |
44124 KB |
Output is correct |
23 |
Correct |
37 ms |
44112 KB |
Output is correct |
24 |
Correct |
36 ms |
44124 KB |
Output is correct |
25 |
Correct |
36 ms |
44124 KB |
Output is correct |
26 |
Correct |
37 ms |
44116 KB |
Output is correct |
27 |
Correct |
40 ms |
42832 KB |
Output is correct |
28 |
Correct |
36 ms |
44112 KB |
Output is correct |
29 |
Correct |
36 ms |
44116 KB |
Output is correct |
30 |
Correct |
36 ms |
43860 KB |
Output is correct |
31 |
Correct |
1053 ms |
187896 KB |
Output is correct |
32 |
Correct |
223 ms |
54892 KB |
Output is correct |
33 |
Correct |
1024 ms |
185332 KB |
Output is correct |
34 |
Correct |
957 ms |
185072 KB |
Output is correct |
35 |
Correct |
1089 ms |
188660 KB |
Output is correct |
36 |
Correct |
1126 ms |
188912 KB |
Output is correct |
37 |
Correct |
805 ms |
183796 KB |
Output is correct |
38 |
Correct |
809 ms |
183520 KB |
Output is correct |
39 |
Correct |
596 ms |
182908 KB |
Output is correct |
40 |
Correct |
614 ms |
182708 KB |
Output is correct |
41 |
Correct |
617 ms |
183028 KB |
Output is correct |
42 |
Correct |
598 ms |
183812 KB |
Output is correct |
43 |
Correct |
225 ms |
56180 KB |
Output is correct |
44 |
Correct |
613 ms |
183536 KB |
Output is correct |
45 |
Correct |
630 ms |
182020 KB |
Output is correct |
46 |
Correct |
639 ms |
182076 KB |
Output is correct |
47 |
Correct |
462 ms |
177648 KB |
Output is correct |
48 |
Correct |
469 ms |
176112 KB |
Output is correct |
49 |
Correct |
533 ms |
178176 KB |
Output is correct |
50 |
Correct |
535 ms |
182068 KB |
Output is correct |
51 |
Correct |
540 ms |
178808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3401 ms |
636624 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
622940 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5077 ms |
630652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
42580 KB |
Output is correct |
2 |
Correct |
32 ms |
42580 KB |
Output is correct |
3 |
Correct |
33 ms |
42576 KB |
Output is correct |
4 |
Correct |
34 ms |
42588 KB |
Output is correct |
5 |
Correct |
34 ms |
42684 KB |
Output is correct |
6 |
Correct |
36 ms |
44112 KB |
Output is correct |
7 |
Correct |
36 ms |
43980 KB |
Output is correct |
8 |
Correct |
36 ms |
44124 KB |
Output is correct |
9 |
Correct |
47 ms |
44028 KB |
Output is correct |
10 |
Correct |
36 ms |
43996 KB |
Output is correct |
11 |
Correct |
37 ms |
44116 KB |
Output is correct |
12 |
Correct |
35 ms |
44120 KB |
Output is correct |
13 |
Correct |
36 ms |
44120 KB |
Output is correct |
14 |
Correct |
37 ms |
43984 KB |
Output is correct |
15 |
Correct |
37 ms |
44024 KB |
Output is correct |
16 |
Correct |
37 ms |
44112 KB |
Output is correct |
17 |
Correct |
38 ms |
44252 KB |
Output is correct |
18 |
Correct |
40 ms |
44124 KB |
Output is correct |
19 |
Correct |
36 ms |
44116 KB |
Output is correct |
20 |
Correct |
38 ms |
44168 KB |
Output is correct |
21 |
Correct |
36 ms |
42832 KB |
Output is correct |
22 |
Correct |
37 ms |
44124 KB |
Output is correct |
23 |
Correct |
37 ms |
44112 KB |
Output is correct |
24 |
Correct |
36 ms |
44124 KB |
Output is correct |
25 |
Correct |
36 ms |
44124 KB |
Output is correct |
26 |
Correct |
37 ms |
44116 KB |
Output is correct |
27 |
Correct |
40 ms |
42832 KB |
Output is correct |
28 |
Correct |
36 ms |
44112 KB |
Output is correct |
29 |
Correct |
36 ms |
44116 KB |
Output is correct |
30 |
Correct |
36 ms |
43860 KB |
Output is correct |
31 |
Correct |
1053 ms |
187896 KB |
Output is correct |
32 |
Correct |
223 ms |
54892 KB |
Output is correct |
33 |
Correct |
1024 ms |
185332 KB |
Output is correct |
34 |
Correct |
957 ms |
185072 KB |
Output is correct |
35 |
Correct |
1089 ms |
188660 KB |
Output is correct |
36 |
Correct |
1126 ms |
188912 KB |
Output is correct |
37 |
Correct |
805 ms |
183796 KB |
Output is correct |
38 |
Correct |
809 ms |
183520 KB |
Output is correct |
39 |
Correct |
596 ms |
182908 KB |
Output is correct |
40 |
Correct |
614 ms |
182708 KB |
Output is correct |
41 |
Correct |
617 ms |
183028 KB |
Output is correct |
42 |
Correct |
598 ms |
183812 KB |
Output is correct |
43 |
Correct |
225 ms |
56180 KB |
Output is correct |
44 |
Correct |
613 ms |
183536 KB |
Output is correct |
45 |
Correct |
630 ms |
182020 KB |
Output is correct |
46 |
Correct |
639 ms |
182076 KB |
Output is correct |
47 |
Correct |
462 ms |
177648 KB |
Output is correct |
48 |
Correct |
469 ms |
176112 KB |
Output is correct |
49 |
Correct |
533 ms |
178176 KB |
Output is correct |
50 |
Correct |
535 ms |
182068 KB |
Output is correct |
51 |
Correct |
540 ms |
178808 KB |
Output is correct |
52 |
Correct |
725 ms |
191852 KB |
Output is correct |
53 |
Correct |
766 ms |
186556 KB |
Output is correct |
54 |
Correct |
790 ms |
188988 KB |
Output is correct |
55 |
Correct |
673 ms |
183528 KB |
Output is correct |
56 |
Correct |
666 ms |
183960 KB |
Output is correct |
57 |
Correct |
658 ms |
184568 KB |
Output is correct |
58 |
Correct |
652 ms |
184304 KB |
Output is correct |
59 |
Correct |
678 ms |
182264 KB |
Output is correct |
60 |
Correct |
670 ms |
184540 KB |
Output is correct |
61 |
Correct |
396 ms |
69400 KB |
Output is correct |
62 |
Correct |
746 ms |
190636 KB |
Output is correct |
63 |
Correct |
801 ms |
188556 KB |
Output is correct |
64 |
Correct |
779 ms |
187964 KB |
Output is correct |
65 |
Correct |
766 ms |
184168 KB |
Output is correct |
66 |
Correct |
654 ms |
183996 KB |
Output is correct |
67 |
Correct |
387 ms |
60400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
42580 KB |
Output is correct |
2 |
Correct |
32 ms |
42580 KB |
Output is correct |
3 |
Correct |
33 ms |
42576 KB |
Output is correct |
4 |
Correct |
34 ms |
42588 KB |
Output is correct |
5 |
Correct |
34 ms |
42684 KB |
Output is correct |
6 |
Correct |
36 ms |
44112 KB |
Output is correct |
7 |
Correct |
36 ms |
43980 KB |
Output is correct |
8 |
Correct |
36 ms |
44124 KB |
Output is correct |
9 |
Correct |
47 ms |
44028 KB |
Output is correct |
10 |
Correct |
36 ms |
43996 KB |
Output is correct |
11 |
Correct |
37 ms |
44116 KB |
Output is correct |
12 |
Correct |
35 ms |
44120 KB |
Output is correct |
13 |
Correct |
36 ms |
44120 KB |
Output is correct |
14 |
Correct |
37 ms |
43984 KB |
Output is correct |
15 |
Correct |
37 ms |
44024 KB |
Output is correct |
16 |
Correct |
37 ms |
44112 KB |
Output is correct |
17 |
Correct |
38 ms |
44252 KB |
Output is correct |
18 |
Correct |
40 ms |
44124 KB |
Output is correct |
19 |
Correct |
36 ms |
44116 KB |
Output is correct |
20 |
Correct |
38 ms |
44168 KB |
Output is correct |
21 |
Correct |
36 ms |
42832 KB |
Output is correct |
22 |
Correct |
37 ms |
44124 KB |
Output is correct |
23 |
Correct |
37 ms |
44112 KB |
Output is correct |
24 |
Correct |
36 ms |
44124 KB |
Output is correct |
25 |
Correct |
36 ms |
44124 KB |
Output is correct |
26 |
Correct |
37 ms |
44116 KB |
Output is correct |
27 |
Correct |
40 ms |
42832 KB |
Output is correct |
28 |
Correct |
36 ms |
44112 KB |
Output is correct |
29 |
Correct |
36 ms |
44116 KB |
Output is correct |
30 |
Correct |
36 ms |
43860 KB |
Output is correct |
31 |
Correct |
1053 ms |
187896 KB |
Output is correct |
32 |
Correct |
223 ms |
54892 KB |
Output is correct |
33 |
Correct |
1024 ms |
185332 KB |
Output is correct |
34 |
Correct |
957 ms |
185072 KB |
Output is correct |
35 |
Correct |
1089 ms |
188660 KB |
Output is correct |
36 |
Correct |
1126 ms |
188912 KB |
Output is correct |
37 |
Correct |
805 ms |
183796 KB |
Output is correct |
38 |
Correct |
809 ms |
183520 KB |
Output is correct |
39 |
Correct |
596 ms |
182908 KB |
Output is correct |
40 |
Correct |
614 ms |
182708 KB |
Output is correct |
41 |
Correct |
617 ms |
183028 KB |
Output is correct |
42 |
Correct |
598 ms |
183812 KB |
Output is correct |
43 |
Correct |
225 ms |
56180 KB |
Output is correct |
44 |
Correct |
613 ms |
183536 KB |
Output is correct |
45 |
Correct |
630 ms |
182020 KB |
Output is correct |
46 |
Correct |
639 ms |
182076 KB |
Output is correct |
47 |
Correct |
462 ms |
177648 KB |
Output is correct |
48 |
Correct |
469 ms |
176112 KB |
Output is correct |
49 |
Correct |
533 ms |
178176 KB |
Output is correct |
50 |
Correct |
535 ms |
182068 KB |
Output is correct |
51 |
Correct |
540 ms |
178808 KB |
Output is correct |
52 |
Correct |
3401 ms |
636624 KB |
Output is correct |
53 |
Execution timed out |
5061 ms |
622940 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |