#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()
#define INF 1e18
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace seg {
int n;
vector<int> seg;
void init_(int _n) {
n = _n;
seg.assign(2 * n + 1, INF);
}
inline int get(int L, int R) {
return (L + R) | (L != R);
}
void pull(int L, int R) {
int nd = get(L, R), mid = (L + R) / 2;
seg[nd] = min(seg[get(L, mid)], seg[get(mid + 1, R)]);
}
void modify(int L, int R, int id, int v) {
int nd = get(L, R), mid = (L + R) / 2;
if(L == R) seg[nd] = v;
else {
if(id <= mid) modify(L, mid, id, v);
else modify(mid + 1, R, id, v);
pull(L, R);
}
}
int query(int L, int R, int l, int r) {
int nd = get(L, R), mid = (L + R) / 2;
if(l > R || r < L) return INF;
else if(l <= L && r >= R) return seg[nd];
else return min(query(L, mid, l, r), query(mid + 1, R, l, r));
}
void change(int x, int v) {modify(1, n, x, v);}
int ask(int x) { return query(1, n, x, n); }
};
namespace solver {
int n, k, q;
struct query {
int x, tp, id;
bool operator<(query b) {
if(x != b.x) return x < b.x;
else return tp < b.tp;
}
};
vector<map<int, int>> s;
vector<multiset<pii>> cur;
vector<pii> ans, stores;
vector<query> qq;
vector<int> v;
void init_(int _n, int _k, int _q) {
n = _n, k = _k, q = _q;
s.assign(k + 1, map<int, int>());
cur.assign(n + q + 2, multiset<pii>());
ans.assign(q + 1, {0, 0});
stores.assign(n + k + 1, {0, 0});
qq.clear(), v.clear();
seg::init_(n + q + 1);
}
void add_store(int id, int l, int tp, int a, int b) {
stores[id] = {l, tp};
v.push_back(l);
qq.push_back({a, 1, id});
qq.push_back({b + 1, 2, id});
}
void add_query(int id, int l, int y) {
ans[id].first = l;
v.push_back(l);
qq.push_back({y, 3, id});
}
void update(int x) {
auto it = cur[x].begin();
if(it == cur[x].end()) seg::change(x, INF);
else seg::change(x, it -> first);
}
void add(int id) {
int tp = stores[id].second, l = stores[id].first;
s[tp][l] ++;
if(s[tp][l] > 1) return;
int pre, nxt = 0;
auto it1 = s[tp].upper_bound(l);
auto it2 = s[tp].lower_bound(l);
if(it2 == s[tp].begin()) pre = 0;
else pre = prev(it2) -> first;
if(it1 != s[tp].end()) {
nxt = it1 -> first;
cur[nxt].erase(cur[nxt].find({pre, tp}));
cur[nxt].insert({l, tp});
update(nxt);
}
cur[l].insert({pre, tp});
update(l);
}
void remove(int id) {
int tp = stores[id].second, l = stores[id].first;
s[tp][l] --;
if(s[tp][l] > 0) return;
int pre, nxt;
s[tp].erase(s[tp].find(l));
auto it1 = s[tp].upper_bound(l);
auto it2 = s[tp].lower_bound(l);
if(it2 == s[tp].begin()) pre = 0;
else pre = prev(it2) -> first;
if(it1 != s[tp].end()) {
nxt = it1 -> first;
cur[nxt].erase(cur[nxt].find({l, tp}));
cur[nxt].insert({pre, tp});
update(nxt);
}
cur[l].erase({pre, tp});
update(l);
}
int query(int x) {
int L = -1, R = 1e9;
while(R - L > 1) {
int mid = (L + R) / 2;
int l = lower_bound(all(v), v[x] - mid) - v.begin();
int r = upper_bound(all(v), v[x] + mid) - v.begin() - 1;
int val = seg::ask(r + 1);
if(val < l) L = mid;
else R = mid;
}
if(R == 1e9) return -1;
else return R;
}
void solve() {
rep(i, 1, k) add_store(n + i, INF, i, -INF, INF);
v.push_back(-INF);
sort(all(v)), v.resize(unique(all(v)) - v.begin());
rep(i, 1, n + k) stores[i].first = lower_bound(all(v), stores[i].first) - v.begin();
rep(i, 1, q) ans[i].first = lower_bound(all(v), ans[i].first) - v.begin();
sort(all(qq));
for(auto i : qq) {
if(i.tp == 1) add(i.id);
else if(i.tp == 2) remove(i.id);
else ans[i.id].second = query(ans[i.id].first);
}
rep(i, 1, q) cout << ans[i].second << "\n";
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, k, q; cin >> n >> k >> q;
init_(n, k, q);
rep(i ,1, n) {
int x, t, a, b;
cin >> x >> t >> a >> b;
add_store(i, x, t, a, b);
}
rep(i, 1, q) {
int l, y; cin >> l >> y;
add_query(i, l, y);
}
solve();
return 0;
}
Compilation message
new_home.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
new_home.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
new_home.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
456 KB |
Output is correct |
9 |
Correct |
3 ms |
572 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
452 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
448 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
4 ms |
452 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
3 ms |
448 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
456 KB |
Output is correct |
9 |
Correct |
3 ms |
572 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
452 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
448 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
4 ms |
452 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
3 ms |
448 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
428 KB |
Output is correct |
31 |
Correct |
1018 ms |
25896 KB |
Output is correct |
32 |
Correct |
322 ms |
18292 KB |
Output is correct |
33 |
Correct |
1045 ms |
20784 KB |
Output is correct |
34 |
Correct |
972 ms |
21120 KB |
Output is correct |
35 |
Correct |
1061 ms |
25828 KB |
Output is correct |
36 |
Correct |
1053 ms |
25640 KB |
Output is correct |
37 |
Correct |
925 ms |
19572 KB |
Output is correct |
38 |
Correct |
881 ms |
19572 KB |
Output is correct |
39 |
Correct |
834 ms |
19612 KB |
Output is correct |
40 |
Correct |
853 ms |
19580 KB |
Output is correct |
41 |
Correct |
661 ms |
19668 KB |
Output is correct |
42 |
Correct |
637 ms |
19700 KB |
Output is correct |
43 |
Correct |
395 ms |
19316 KB |
Output is correct |
44 |
Correct |
702 ms |
19552 KB |
Output is correct |
45 |
Correct |
695 ms |
19572 KB |
Output is correct |
46 |
Correct |
756 ms |
19568 KB |
Output is correct |
47 |
Correct |
632 ms |
19516 KB |
Output is correct |
48 |
Correct |
673 ms |
19312 KB |
Output is correct |
49 |
Correct |
672 ms |
19376 KB |
Output is correct |
50 |
Correct |
646 ms |
19524 KB |
Output is correct |
51 |
Correct |
712 ms |
19420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4870 ms |
141572 KB |
Output is correct |
2 |
Execution timed out |
5015 ms |
123100 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5103 ms |
125164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
456 KB |
Output is correct |
9 |
Correct |
3 ms |
572 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
452 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
448 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
4 ms |
452 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
3 ms |
448 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
428 KB |
Output is correct |
31 |
Correct |
1018 ms |
25896 KB |
Output is correct |
32 |
Correct |
322 ms |
18292 KB |
Output is correct |
33 |
Correct |
1045 ms |
20784 KB |
Output is correct |
34 |
Correct |
972 ms |
21120 KB |
Output is correct |
35 |
Correct |
1061 ms |
25828 KB |
Output is correct |
36 |
Correct |
1053 ms |
25640 KB |
Output is correct |
37 |
Correct |
925 ms |
19572 KB |
Output is correct |
38 |
Correct |
881 ms |
19572 KB |
Output is correct |
39 |
Correct |
834 ms |
19612 KB |
Output is correct |
40 |
Correct |
853 ms |
19580 KB |
Output is correct |
41 |
Correct |
661 ms |
19668 KB |
Output is correct |
42 |
Correct |
637 ms |
19700 KB |
Output is correct |
43 |
Correct |
395 ms |
19316 KB |
Output is correct |
44 |
Correct |
702 ms |
19552 KB |
Output is correct |
45 |
Correct |
695 ms |
19572 KB |
Output is correct |
46 |
Correct |
756 ms |
19568 KB |
Output is correct |
47 |
Correct |
632 ms |
19516 KB |
Output is correct |
48 |
Correct |
673 ms |
19312 KB |
Output is correct |
49 |
Correct |
672 ms |
19376 KB |
Output is correct |
50 |
Correct |
646 ms |
19524 KB |
Output is correct |
51 |
Correct |
712 ms |
19420 KB |
Output is correct |
52 |
Correct |
961 ms |
40140 KB |
Output is correct |
53 |
Correct |
892 ms |
35532 KB |
Output is correct |
54 |
Correct |
769 ms |
30436 KB |
Output is correct |
55 |
Correct |
763 ms |
25852 KB |
Output is correct |
56 |
Correct |
860 ms |
29524 KB |
Output is correct |
57 |
Correct |
752 ms |
20712 KB |
Output is correct |
58 |
Correct |
793 ms |
25820 KB |
Output is correct |
59 |
Correct |
784 ms |
29380 KB |
Output is correct |
60 |
Correct |
688 ms |
20584 KB |
Output is correct |
61 |
Correct |
583 ms |
40024 KB |
Output is correct |
62 |
Correct |
911 ms |
40284 KB |
Output is correct |
63 |
Correct |
823 ms |
31788 KB |
Output is correct |
64 |
Correct |
759 ms |
28120 KB |
Output is correct |
65 |
Correct |
699 ms |
21580 KB |
Output is correct |
66 |
Correct |
764 ms |
19816 KB |
Output is correct |
67 |
Correct |
577 ms |
19600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
456 KB |
Output is correct |
9 |
Correct |
3 ms |
572 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
452 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
448 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
4 ms |
452 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
4 ms |
588 KB |
Output is correct |
23 |
Correct |
3 ms |
448 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
428 KB |
Output is correct |
31 |
Correct |
1018 ms |
25896 KB |
Output is correct |
32 |
Correct |
322 ms |
18292 KB |
Output is correct |
33 |
Correct |
1045 ms |
20784 KB |
Output is correct |
34 |
Correct |
972 ms |
21120 KB |
Output is correct |
35 |
Correct |
1061 ms |
25828 KB |
Output is correct |
36 |
Correct |
1053 ms |
25640 KB |
Output is correct |
37 |
Correct |
925 ms |
19572 KB |
Output is correct |
38 |
Correct |
881 ms |
19572 KB |
Output is correct |
39 |
Correct |
834 ms |
19612 KB |
Output is correct |
40 |
Correct |
853 ms |
19580 KB |
Output is correct |
41 |
Correct |
661 ms |
19668 KB |
Output is correct |
42 |
Correct |
637 ms |
19700 KB |
Output is correct |
43 |
Correct |
395 ms |
19316 KB |
Output is correct |
44 |
Correct |
702 ms |
19552 KB |
Output is correct |
45 |
Correct |
695 ms |
19572 KB |
Output is correct |
46 |
Correct |
756 ms |
19568 KB |
Output is correct |
47 |
Correct |
632 ms |
19516 KB |
Output is correct |
48 |
Correct |
673 ms |
19312 KB |
Output is correct |
49 |
Correct |
672 ms |
19376 KB |
Output is correct |
50 |
Correct |
646 ms |
19524 KB |
Output is correct |
51 |
Correct |
712 ms |
19420 KB |
Output is correct |
52 |
Correct |
4870 ms |
141572 KB |
Output is correct |
53 |
Execution timed out |
5015 ms |
123100 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |