#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<int,int> pii;
using namespace std;
const int N = 100'010;
const int S = 1000;
vector<pair<int,int>> T[N];
vector<tuple<int,int,int>> Ah[(1<<27)/24];
int nxt = 0;
set<pii> A[N];
int h[N];
int n;
void init(int N, int D, int H[]) {
n = N;
Loop (i,0,n) {
h[i] = H[i];
T[i].push_back({0, nxt++});
}
}
void flush(int i, int t, bool nw)
{
for (auto [x, y] : A[i])
Ah[T[i].back().second].push_back({h[x], y, t});
if (nw)
T[i].push_back({t, nxt++});
}
void up(int i, int j, int t)
{
auto it = A[i].lower_bound(pii{j, 0});
if (it == A[i].end() || it->first != j) {
A[i].insert({j, t});
} else {
Ah[T[i].back().second].push_back({h[j], it->second, t});
A[i].erase(it);
}
if (A[i].size() + A[T[i].back().second].size() > S)
flush(i, t, 1);
}
void curseChanges(int U, int A[], int B[]) {
Loop (i,0,U) {
up(A[i], B[i], i+1);
up(B[i], A[i], i+1);
}
Loop (i,0,n)
flush(i, U+1, 0);
Loop (i,0,nxt) {
sort(Ah[i].begin(), Ah[i].end());
//cout << i << ":\n";
//for (auto [h, l, r] : Ah[i])
// cout << h << ' ' << l << ' ' << r << '\n';
//cout << '\n';
}
}
vector<tuple<int,int,int>> &get_vec(int x, int t)
{
auto it = --upper_bound(T[x].begin(), T[x].end(), pii{t, INT_MAX});
return Ah[it->second];
}
int solve(const vector<tuple<int,int,int>> &a, const vector<tuple<int,int,int>> &b, int t) {
int ans = 1e9;
int p0 = 0, p1 = 0;
while (p0 < a.size() && p1 < b.size()) {
auto [h1, l1, r1] = a[p0];
auto [h2, l2, r2] = b[p1];
if (!(l1 <= t && t < r1)) {
++p0;
continue;
}
if (!(l2 <= t && t < r2)) {
++p1;
continue;
}
ans = min(ans, abs(h2 - h1));
(h1 < h2? p0: p1)++;
}
return ans;
}
int question(int x, int y, int v) {
return solve(get_vec(x, v), get_vec(y, v), v);
}
Compilation message
potion.cpp: In function 'int solve(const std::vector<std::tuple<int, int, int> >&, const std::vector<std::tuple<int, int, int> >&, int)':
potion.cpp:70:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while (p0 < a.size() && p1 < b.size()) {
| ~~~^~~~~~~~~~
potion.cpp:70:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while (p0 < a.size() && p1 < b.size()) {
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
138620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
138792 KB |
Output is correct |
2 |
Correct |
66 ms |
138788 KB |
Output is correct |
3 |
Correct |
65 ms |
138756 KB |
Output is correct |
4 |
Correct |
81 ms |
142668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
170252 KB |
Output is correct |
2 |
Correct |
352 ms |
170328 KB |
Output is correct |
3 |
Correct |
481 ms |
147116 KB |
Output is correct |
4 |
Correct |
516 ms |
156352 KB |
Output is correct |
5 |
Correct |
332 ms |
166532 KB |
Output is correct |
6 |
Correct |
942 ms |
154428 KB |
Output is correct |
7 |
Correct |
371 ms |
154164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
170352 KB |
Output is correct |
2 |
Correct |
673 ms |
147792 KB |
Output is correct |
3 |
Correct |
415 ms |
154792 KB |
Output is correct |
4 |
Correct |
581 ms |
154444 KB |
Output is correct |
5 |
Correct |
452 ms |
169804 KB |
Output is correct |
6 |
Correct |
569 ms |
154436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
140376 KB |
Output is correct |
2 |
Correct |
107 ms |
139300 KB |
Output is correct |
3 |
Correct |
220 ms |
139216 KB |
Output is correct |
4 |
Correct |
299 ms |
139932 KB |
Output is correct |
5 |
Correct |
248 ms |
140264 KB |
Output is correct |
6 |
Correct |
123 ms |
140008 KB |
Output is correct |
7 |
Correct |
560 ms |
139400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
138620 KB |
Output is correct |
2 |
Correct |
64 ms |
138792 KB |
Output is correct |
3 |
Correct |
66 ms |
138788 KB |
Output is correct |
4 |
Correct |
65 ms |
138756 KB |
Output is correct |
5 |
Correct |
81 ms |
142668 KB |
Output is correct |
6 |
Correct |
398 ms |
170252 KB |
Output is correct |
7 |
Correct |
352 ms |
170328 KB |
Output is correct |
8 |
Correct |
481 ms |
147116 KB |
Output is correct |
9 |
Correct |
516 ms |
156352 KB |
Output is correct |
10 |
Correct |
332 ms |
166532 KB |
Output is correct |
11 |
Correct |
942 ms |
154428 KB |
Output is correct |
12 |
Correct |
371 ms |
154164 KB |
Output is correct |
13 |
Correct |
396 ms |
170352 KB |
Output is correct |
14 |
Correct |
673 ms |
147792 KB |
Output is correct |
15 |
Correct |
415 ms |
154792 KB |
Output is correct |
16 |
Correct |
581 ms |
154444 KB |
Output is correct |
17 |
Correct |
452 ms |
169804 KB |
Output is correct |
18 |
Correct |
569 ms |
154436 KB |
Output is correct |
19 |
Correct |
93 ms |
140376 KB |
Output is correct |
20 |
Correct |
107 ms |
139300 KB |
Output is correct |
21 |
Correct |
220 ms |
139216 KB |
Output is correct |
22 |
Correct |
299 ms |
139932 KB |
Output is correct |
23 |
Correct |
248 ms |
140264 KB |
Output is correct |
24 |
Correct |
123 ms |
140008 KB |
Output is correct |
25 |
Correct |
560 ms |
139400 KB |
Output is correct |
26 |
Correct |
443 ms |
147728 KB |
Output is correct |
27 |
Correct |
616 ms |
154796 KB |
Output is correct |
28 |
Correct |
569 ms |
163656 KB |
Output is correct |
29 |
Correct |
497 ms |
156512 KB |
Output is correct |
30 |
Correct |
930 ms |
154248 KB |
Output is correct |
31 |
Correct |
1416 ms |
147672 KB |
Output is correct |
32 |
Correct |
907 ms |
154340 KB |
Output is correct |