Submission #1008384

# Submission time Handle Problem Language Result Execution time Memory
1008384 2024-06-26T10:24:08 Z LonlyR New Home (APIO18_new_home) C++17
100 / 100
2627 ms 165776 KB
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
 
using namespace std;
const int maxn = 6e5 + 5, inf = 1e8;
int n, k, q, cnt, m;
int mark[maxn], ans[maxn];
vector<int> nen;
array<int, 3> qr[maxn];
array<int, 4> store[maxn];
vector<array<int, 5>> seg;
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> bound_right;
multiset<int> type[maxn], segment[maxn];
int st[4 * maxn];
 
void upd(int pos, int id = 1, int l = 1, int r = m)
{
    if (l == r) return void(st[id] = (segment[l].size() ? *segment[r].rbegin() : 0));
    int mid = (l + r) / 2;
    if (pos <= mid) upd(pos, id * 2, l, mid);
    else upd(pos, id * 2 + 1, mid + 1, r);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
 
int get(int pos, int id = 1, int l = 1, int r = m)
{
    if (l == r) return st[id];
    int mid = (l + r) / 2;
    if (pos <= mid) return get(pos, id * 2, l, mid);
    return max(st[id * 2], get(pos, id * 2 + 1, mid + 1, r));
}
 
void add_seg(int l, int r)
{
    l = upper_bound(all(nen), l) - nen.begin();
    segment[l].emplace(r);
    upd(l);
}
 
void del_seg(int l, int r)
{
    l = upper_bound(all(nen), l) - nen.begin();
    segment[l].erase(segment[l].find(r));
    upd(l);
}
 
set<int> naww;
 
void add(int id)
{
    auto [x, t, l, r] = store[id];
    l = 1, r = inf;
    auto it = type[t].lower_bound(x);
    if (it != type[t].end()) r = *it - 1;
    if (it != type[t].begin()) l = *prev(it) + 1;
    type[t].emplace(x);
    del_seg(l, r);
    add_seg(l, x - 1);
    add_seg(x + 1, r);
}
 
void del(int id)
{
    auto [x, t, l, r] = store[id];
    l = 1, r = inf;
    auto it = type[t].lower_bound(x);
    if (next(it) != type[t].end()) r = *next(it) - 1;
    if (it != type[t].begin()) l = *prev(it) + 1;
    type[t].erase(it);
    del_seg(l, x - 1);
    del_seg(x + 1, r);
    add_seg(l, r);
}
 
int get_ans(int x)
{
    int l = 0, r = inf, ans = -1;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        int lx = max(1ll, x - mid), rx = min(inf, x + mid);
        int pos = upper_bound(all(nen), lx) - nen.begin();
        if (get(pos) >= rx) l = mid + 1;
        else ans = mid, r = mid - 1;
    }
    return ans;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    freopen("test.inp", "r", stdin);
//    freopen("AC.out", "w", stdout);
    cin >> n >> k >> q;
    nen = {1};
    for (int i = 1; i <= n; i++)
    {
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        store[i] = {x, t, a, b};
        nen.emplace_back(x + 1);
    }
    for (int i = 1, x, t; i <= q; i++)
        cin >> x >> t,
        qr[i] = {t, x, i};
    sort(all(nen));
    nen.resize(unique(all(nen)) - nen.begin());
    m = nen.size();
    for (int i = 1; i <= n; i++)
    {
        auto [x, t, l, r] = store[i];
        seg.push_back({x, t, l, r, i});
    }
    sort(all(seg),[](array<int, 5> x, array<int, 5> y)
         {
             if (x[2] != y[2]) return x[2] < y[2];
             return x[3] < y[3];
         });
    for (int i = 1; i <= k; i++)
        segment[1].emplace(inf);
    upd(1);
    sort(qr + 1, qr + q + 1);
    memset(ans, -1, sizeof ans);
    for (int i = 1, it = 0; i <= q; i++)
    {
        auto [time, pos, id] = qr[i];
        while (it < seg.size() && seg[it][2] <= time)
            add(seg[it][4]),
            bound_right.emplace(seg[it][3], seg[it][4]),
            it++;
        while (bound_right.size() && bound_right.top().first < time)
            del(bound_right.top().second),
            bound_right.pop();
        ans[id] = get_ans(pos);
    }
    for (int i = 1; i <= q; i++)
        cout << ans[i] << "\n";
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:129:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 5> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |         while (it < seg.size() && seg[it][2] <= time)
      |                ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 63580 KB Output is correct
2 Correct 22 ms 63580 KB Output is correct
3 Correct 22 ms 63476 KB Output is correct
4 Correct 23 ms 63580 KB Output is correct
5 Correct 22 ms 63700 KB Output is correct
6 Correct 24 ms 63640 KB Output is correct
7 Correct 29 ms 63576 KB Output is correct
8 Correct 23 ms 63704 KB Output is correct
9 Correct 25 ms 63720 KB Output is correct
10 Correct 28 ms 63744 KB Output is correct
11 Correct 26 ms 63496 KB Output is correct
12 Correct 27 ms 63696 KB Output is correct
13 Correct 23 ms 63688 KB Output is correct
14 Correct 24 ms 63580 KB Output is correct
15 Correct 29 ms 63664 KB Output is correct
16 Correct 30 ms 63664 KB Output is correct
17 Correct 24 ms 63580 KB Output is correct
18 Correct 24 ms 63572 KB Output is correct
19 Correct 23 ms 63708 KB Output is correct
20 Correct 24 ms 63692 KB Output is correct
21 Correct 25 ms 63712 KB Output is correct
22 Correct 23 ms 63580 KB Output is correct
23 Correct 26 ms 63576 KB Output is correct
24 Correct 25 ms 63640 KB Output is correct
25 Correct 24 ms 63608 KB Output is correct
26 Correct 24 ms 63668 KB Output is correct
27 Correct 23 ms 63528 KB Output is correct
28 Correct 24 ms 63588 KB Output is correct
29 Correct 26 ms 63704 KB Output is correct
30 Correct 24 ms 63488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 63580 KB Output is correct
2 Correct 22 ms 63580 KB Output is correct
3 Correct 22 ms 63476 KB Output is correct
4 Correct 23 ms 63580 KB Output is correct
5 Correct 22 ms 63700 KB Output is correct
6 Correct 24 ms 63640 KB Output is correct
7 Correct 29 ms 63576 KB Output is correct
8 Correct 23 ms 63704 KB Output is correct
9 Correct 25 ms 63720 KB Output is correct
10 Correct 28 ms 63744 KB Output is correct
11 Correct 26 ms 63496 KB Output is correct
12 Correct 27 ms 63696 KB Output is correct
13 Correct 23 ms 63688 KB Output is correct
14 Correct 24 ms 63580 KB Output is correct
15 Correct 29 ms 63664 KB Output is correct
16 Correct 30 ms 63664 KB Output is correct
17 Correct 24 ms 63580 KB Output is correct
18 Correct 24 ms 63572 KB Output is correct
19 Correct 23 ms 63708 KB Output is correct
20 Correct 24 ms 63692 KB Output is correct
21 Correct 25 ms 63712 KB Output is correct
22 Correct 23 ms 63580 KB Output is correct
23 Correct 26 ms 63576 KB Output is correct
24 Correct 25 ms 63640 KB Output is correct
25 Correct 24 ms 63608 KB Output is correct
26 Correct 24 ms 63668 KB Output is correct
27 Correct 23 ms 63528 KB Output is correct
28 Correct 24 ms 63588 KB Output is correct
29 Correct 26 ms 63704 KB Output is correct
30 Correct 24 ms 63488 KB Output is correct
31 Correct 420 ms 79596 KB Output is correct
32 Correct 145 ms 72968 KB Output is correct
33 Correct 415 ms 75380 KB Output is correct
34 Correct 371 ms 75660 KB Output is correct
35 Correct 389 ms 79624 KB Output is correct
36 Correct 386 ms 79624 KB Output is correct
37 Correct 337 ms 73452 KB Output is correct
38 Correct 317 ms 73540 KB Output is correct
39 Correct 260 ms 73316 KB Output is correct
40 Correct 261 ms 73248 KB Output is correct
41 Correct 232 ms 73728 KB Output is correct
42 Correct 203 ms 73204 KB Output is correct
43 Correct 87 ms 78272 KB Output is correct
44 Correct 237 ms 73588 KB Output is correct
45 Correct 236 ms 73480 KB Output is correct
46 Correct 254 ms 73368 KB Output is correct
47 Correct 198 ms 72904 KB Output is correct
48 Correct 222 ms 72704 KB Output is correct
49 Correct 223 ms 72968 KB Output is correct
50 Correct 225 ms 73176 KB Output is correct
51 Correct 246 ms 72924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1084 ms 153788 KB Output is correct
2 Correct 1757 ms 148704 KB Output is correct
3 Correct 1072 ms 165524 KB Output is correct
4 Correct 1096 ms 155788 KB Output is correct
5 Correct 1831 ms 148228 KB Output is correct
6 Correct 1803 ms 148656 KB Output is correct
7 Correct 1043 ms 165516 KB Output is correct
8 Correct 1051 ms 155716 KB Output is correct
9 Correct 1169 ms 152460 KB Output is correct
10 Correct 1793 ms 149908 KB Output is correct
11 Correct 1353 ms 148376 KB Output is correct
12 Correct 1376 ms 149564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2200 ms 150464 KB Output is correct
2 Correct 710 ms 131468 KB Output is correct
3 Correct 2458 ms 148652 KB Output is correct
4 Correct 1512 ms 163340 KB Output is correct
5 Correct 1528 ms 151864 KB Output is correct
6 Correct 1507 ms 153740 KB Output is correct
7 Correct 2424 ms 148112 KB Output is correct
8 Correct 2433 ms 148608 KB Output is correct
9 Correct 1568 ms 164636 KB Output is correct
10 Correct 1772 ms 154004 KB Output is correct
11 Correct 2023 ms 151188 KB Output is correct
12 Correct 2458 ms 149564 KB Output is correct
13 Correct 1406 ms 147344 KB Output is correct
14 Correct 1410 ms 146708 KB Output is correct
15 Correct 1719 ms 148424 KB Output is correct
16 Correct 1840 ms 149352 KB Output is correct
17 Correct 1905 ms 147816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 63580 KB Output is correct
2 Correct 22 ms 63580 KB Output is correct
3 Correct 22 ms 63476 KB Output is correct
4 Correct 23 ms 63580 KB Output is correct
5 Correct 22 ms 63700 KB Output is correct
6 Correct 24 ms 63640 KB Output is correct
7 Correct 29 ms 63576 KB Output is correct
8 Correct 23 ms 63704 KB Output is correct
9 Correct 25 ms 63720 KB Output is correct
10 Correct 28 ms 63744 KB Output is correct
11 Correct 26 ms 63496 KB Output is correct
12 Correct 27 ms 63696 KB Output is correct
13 Correct 23 ms 63688 KB Output is correct
14 Correct 24 ms 63580 KB Output is correct
15 Correct 29 ms 63664 KB Output is correct
16 Correct 30 ms 63664 KB Output is correct
17 Correct 24 ms 63580 KB Output is correct
18 Correct 24 ms 63572 KB Output is correct
19 Correct 23 ms 63708 KB Output is correct
20 Correct 24 ms 63692 KB Output is correct
21 Correct 25 ms 63712 KB Output is correct
22 Correct 23 ms 63580 KB Output is correct
23 Correct 26 ms 63576 KB Output is correct
24 Correct 25 ms 63640 KB Output is correct
25 Correct 24 ms 63608 KB Output is correct
26 Correct 24 ms 63668 KB Output is correct
27 Correct 23 ms 63528 KB Output is correct
28 Correct 24 ms 63588 KB Output is correct
29 Correct 26 ms 63704 KB Output is correct
30 Correct 24 ms 63488 KB Output is correct
31 Correct 420 ms 79596 KB Output is correct
32 Correct 145 ms 72968 KB Output is correct
33 Correct 415 ms 75380 KB Output is correct
34 Correct 371 ms 75660 KB Output is correct
35 Correct 389 ms 79624 KB Output is correct
36 Correct 386 ms 79624 KB Output is correct
37 Correct 337 ms 73452 KB Output is correct
38 Correct 317 ms 73540 KB Output is correct
39 Correct 260 ms 73316 KB Output is correct
40 Correct 261 ms 73248 KB Output is correct
41 Correct 232 ms 73728 KB Output is correct
42 Correct 203 ms 73204 KB Output is correct
43 Correct 87 ms 78272 KB Output is correct
44 Correct 237 ms 73588 KB Output is correct
45 Correct 236 ms 73480 KB Output is correct
46 Correct 254 ms 73368 KB Output is correct
47 Correct 198 ms 72904 KB Output is correct
48 Correct 222 ms 72704 KB Output is correct
49 Correct 223 ms 72968 KB Output is correct
50 Correct 225 ms 73176 KB Output is correct
51 Correct 246 ms 72924 KB Output is correct
52 Correct 260 ms 82232 KB Output is correct
53 Correct 256 ms 78336 KB Output is correct
54 Correct 243 ms 80544 KB Output is correct
55 Correct 269 ms 76724 KB Output is correct
56 Correct 288 ms 78084 KB Output is correct
57 Correct 239 ms 74240 KB Output is correct
58 Correct 278 ms 76292 KB Output is correct
59 Correct 252 ms 78008 KB Output is correct
60 Correct 233 ms 74140 KB Output is correct
61 Correct 103 ms 80936 KB Output is correct
62 Correct 267 ms 82516 KB Output is correct
63 Correct 266 ms 79876 KB Output is correct
64 Correct 257 ms 78340 KB Output is correct
65 Correct 265 ms 75012 KB Output is correct
66 Correct 236 ms 73620 KB Output is correct
67 Correct 166 ms 71944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 63580 KB Output is correct
2 Correct 22 ms 63580 KB Output is correct
3 Correct 22 ms 63476 KB Output is correct
4 Correct 23 ms 63580 KB Output is correct
5 Correct 22 ms 63700 KB Output is correct
6 Correct 24 ms 63640 KB Output is correct
7 Correct 29 ms 63576 KB Output is correct
8 Correct 23 ms 63704 KB Output is correct
9 Correct 25 ms 63720 KB Output is correct
10 Correct 28 ms 63744 KB Output is correct
11 Correct 26 ms 63496 KB Output is correct
12 Correct 27 ms 63696 KB Output is correct
13 Correct 23 ms 63688 KB Output is correct
14 Correct 24 ms 63580 KB Output is correct
15 Correct 29 ms 63664 KB Output is correct
16 Correct 30 ms 63664 KB Output is correct
17 Correct 24 ms 63580 KB Output is correct
18 Correct 24 ms 63572 KB Output is correct
19 Correct 23 ms 63708 KB Output is correct
20 Correct 24 ms 63692 KB Output is correct
21 Correct 25 ms 63712 KB Output is correct
22 Correct 23 ms 63580 KB Output is correct
23 Correct 26 ms 63576 KB Output is correct
24 Correct 25 ms 63640 KB Output is correct
25 Correct 24 ms 63608 KB Output is correct
26 Correct 24 ms 63668 KB Output is correct
27 Correct 23 ms 63528 KB Output is correct
28 Correct 24 ms 63588 KB Output is correct
29 Correct 26 ms 63704 KB Output is correct
30 Correct 24 ms 63488 KB Output is correct
31 Correct 420 ms 79596 KB Output is correct
32 Correct 145 ms 72968 KB Output is correct
33 Correct 415 ms 75380 KB Output is correct
34 Correct 371 ms 75660 KB Output is correct
35 Correct 389 ms 79624 KB Output is correct
36 Correct 386 ms 79624 KB Output is correct
37 Correct 337 ms 73452 KB Output is correct
38 Correct 317 ms 73540 KB Output is correct
39 Correct 260 ms 73316 KB Output is correct
40 Correct 261 ms 73248 KB Output is correct
41 Correct 232 ms 73728 KB Output is correct
42 Correct 203 ms 73204 KB Output is correct
43 Correct 87 ms 78272 KB Output is correct
44 Correct 237 ms 73588 KB Output is correct
45 Correct 236 ms 73480 KB Output is correct
46 Correct 254 ms 73368 KB Output is correct
47 Correct 198 ms 72904 KB Output is correct
48 Correct 222 ms 72704 KB Output is correct
49 Correct 223 ms 72968 KB Output is correct
50 Correct 225 ms 73176 KB Output is correct
51 Correct 246 ms 72924 KB Output is correct
52 Correct 1084 ms 153788 KB Output is correct
53 Correct 1757 ms 148704 KB Output is correct
54 Correct 1072 ms 165524 KB Output is correct
55 Correct 1096 ms 155788 KB Output is correct
56 Correct 1831 ms 148228 KB Output is correct
57 Correct 1803 ms 148656 KB Output is correct
58 Correct 1043 ms 165516 KB Output is correct
59 Correct 1051 ms 155716 KB Output is correct
60 Correct 1169 ms 152460 KB Output is correct
61 Correct 1793 ms 149908 KB Output is correct
62 Correct 1353 ms 148376 KB Output is correct
63 Correct 1376 ms 149564 KB Output is correct
64 Correct 2200 ms 150464 KB Output is correct
65 Correct 710 ms 131468 KB Output is correct
66 Correct 2458 ms 148652 KB Output is correct
67 Correct 1512 ms 163340 KB Output is correct
68 Correct 1528 ms 151864 KB Output is correct
69 Correct 1507 ms 153740 KB Output is correct
70 Correct 2424 ms 148112 KB Output is correct
71 Correct 2433 ms 148608 KB Output is correct
72 Correct 1568 ms 164636 KB Output is correct
73 Correct 1772 ms 154004 KB Output is correct
74 Correct 2023 ms 151188 KB Output is correct
75 Correct 2458 ms 149564 KB Output is correct
76 Correct 1406 ms 147344 KB Output is correct
77 Correct 1410 ms 146708 KB Output is correct
78 Correct 1719 ms 148424 KB Output is correct
79 Correct 1840 ms 149352 KB Output is correct
80 Correct 1905 ms 147816 KB Output is correct
81 Correct 260 ms 82232 KB Output is correct
82 Correct 256 ms 78336 KB Output is correct
83 Correct 243 ms 80544 KB Output is correct
84 Correct 269 ms 76724 KB Output is correct
85 Correct 288 ms 78084 KB Output is correct
86 Correct 239 ms 74240 KB Output is correct
87 Correct 278 ms 76292 KB Output is correct
88 Correct 252 ms 78008 KB Output is correct
89 Correct 233 ms 74140 KB Output is correct
90 Correct 103 ms 80936 KB Output is correct
91 Correct 267 ms 82516 KB Output is correct
92 Correct 266 ms 79876 KB Output is correct
93 Correct 257 ms 78340 KB Output is correct
94 Correct 265 ms 75012 KB Output is correct
95 Correct 236 ms 73620 KB Output is correct
96 Correct 166 ms 71944 KB Output is correct
97 Correct 1803 ms 165264 KB Output is correct
98 Correct 736 ms 115092 KB Output is correct
99 Correct 2562 ms 129328 KB Output is correct
100 Correct 1623 ms 143900 KB Output is correct
101 Correct 1713 ms 155796 KB Output is correct
102 Correct 2627 ms 150704 KB Output is correct
103 Correct 1913 ms 120100 KB Output is correct
104 Correct 1932 ms 119764 KB Output is correct
105 Correct 1631 ms 119696 KB Output is correct
106 Correct 1609 ms 119696 KB Output is correct
107 Correct 1451 ms 135056 KB Output is correct
108 Correct 1568 ms 143044 KB Output is correct
109 Correct 1425 ms 124052 KB Output is correct
110 Correct 1412 ms 136732 KB Output is correct
111 Correct 1537 ms 144276 KB Output is correct
112 Correct 1375 ms 123536 KB Output is correct
113 Correct 473 ms 155740 KB Output is correct
114 Correct 1795 ms 165776 KB Output is correct
115 Correct 1664 ms 152724 KB Output is correct
116 Correct 1651 ms 145040 KB Output is correct
117 Correct 1484 ms 128652 KB Output is correct
118 Correct 1354 ms 121656 KB Output is correct
119 Correct 982 ms 110336 KB Output is correct
120 Correct 928 ms 116364 KB Output is correct
121 Correct 1158 ms 118340 KB Output is correct
122 Correct 1157 ms 118384 KB Output is correct
123 Correct 1230 ms 119440 KB Output is correct
124 Correct 1275 ms 120056 KB Output is correct
125 Correct 1367 ms 119620 KB Output is correct
126 Correct 1162 ms 120204 KB Output is correct