#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
int N, D, H[100005], U, B, uid[200005], udx;
bool mx[200005], my[200005];
pii change[200005];
bool block[2005][200005];
vector<int> v[100005];
vector<int> fri[100005];
map<int, int> mp[100005];
void init(int n, int d, int h[])
{
N = n;
D = d;
for (int i = 0; i < N; i++)
H[i] = h[i];
}
void curseChanges(int u, int a[], int b[])
{
U = u;
B = sqrt((U + 1) / 3);
for (int i = 0; i < U; i++)
{
if (a[i] > b[i])
swap(a[i], b[i]);
change[i].F = a[i];
change[i].S = b[i];
}
for (int i = 0; i < U; i++)
if (mp[a[i]].find(b[i]) != mp[a[i]].end())
uid[i] = mp[a[i]][b[i]];
else
{
mp[a[i]][b[i]] = uid[i] = i;
v[a[i]].emplace_back(i);
fri[a[i]].emplace_back(b[i]);
v[b[i]].emplace_back(i);
fri[b[i]].emplace_back(a[i]);
}
for (int i = 0; i < N; i++)
sort(fri[i].begin(), fri[i].end(), [&](int i1, int i2)
{ return H[i1] < H[i2]; });
for (int i = 1, j = 0; j < U; i++)
{
for (int k = 0; k < U; k++)
block[i][k] = block[i - 1][k];
for (; j < i * B && j < U; j++)
block[i][uid[j]] ^= 1;
}
}
int question(int x, int y, int V)
{
int b = V / B;
vector<ll> sx, sy;
for (int i : v[x])
if (block[b][i])
{
if (change[i].F == x)
mx[change[i].S] = 1;
else
mx[change[i].F] = 1;
}
for (int i : v[y])
if (block[b][i])
{
if (change[i].F == y)
my[change[i].S] = 1;
else
my[change[i].F] = 1;
}
for (int i = b * B; i < V; i++)
{
if (change[i].S == x)
mx[change[i].F] ^= 1;
if (change[i].S == y)
my[change[i].F] ^= 1;
if (change[i].F == x)
mx[change[i].S] ^= 1;
if (change[i].F == y)
my[change[i].S] ^= 1;
}
for (ll i : fri[x])
if (mx[i])
sx.emplace_back(H[i]);
for (ll i : fri[y])
if (my[i])
sy.emplace_back(H[i]);
ll ans = 1e9;
while (!sx.empty() && !sy.empty())
{
ans = min(ans, abs(sx.back() - sy.back()));
if (sx.back() >= sy.back())
sx.pop_back();
else
sy.pop_back();
}
for (ll i : fri[x])
mx[i] = 0;
for (ll i : fri[y])
my[i] = 0;
return ans;
}
/*
6 5 11 4
2 42 1000 54 68 234
0 1 2 0 3 4 3 5 3 5 1 3 5 3 0 5 3 0 1 3 3 5
0 3 4 26
3 0 8 0
0 5 5 1000000000
3 0 11 14
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
10056 KB |
Output is correct |
2 |
Correct |
7 ms |
10056 KB |
Output is correct |
3 |
Correct |
10 ms |
10056 KB |
Output is correct |
4 |
Correct |
23 ms |
11200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
499 ms |
184260 KB |
Output is correct |
2 |
Correct |
489 ms |
184384 KB |
Output is correct |
3 |
Correct |
272 ms |
166708 KB |
Output is correct |
4 |
Correct |
1201 ms |
176020 KB |
Output is correct |
5 |
Correct |
520 ms |
180192 KB |
Output is correct |
6 |
Correct |
2420 ms |
177188 KB |
Output is correct |
7 |
Correct |
659 ms |
177352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
526 ms |
184272 KB |
Output is correct |
2 |
Correct |
1759 ms |
171840 KB |
Output is correct |
3 |
Correct |
1571 ms |
177164 KB |
Output is correct |
4 |
Correct |
2438 ms |
177048 KB |
Output is correct |
5 |
Correct |
676 ms |
184120 KB |
Output is correct |
6 |
Correct |
2687 ms |
177188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
13512 KB |
Output is correct |
2 |
Correct |
110 ms |
12744 KB |
Output is correct |
3 |
Correct |
150 ms |
12496 KB |
Output is correct |
4 |
Correct |
575 ms |
13256 KB |
Output is correct |
5 |
Correct |
521 ms |
13364 KB |
Output is correct |
6 |
Correct |
104 ms |
13128 KB |
Output is correct |
7 |
Correct |
522 ms |
12616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
6 ms |
10056 KB |
Output is correct |
3 |
Correct |
7 ms |
10056 KB |
Output is correct |
4 |
Correct |
10 ms |
10056 KB |
Output is correct |
5 |
Correct |
23 ms |
11200 KB |
Output is correct |
6 |
Correct |
499 ms |
184260 KB |
Output is correct |
7 |
Correct |
489 ms |
184384 KB |
Output is correct |
8 |
Correct |
272 ms |
166708 KB |
Output is correct |
9 |
Correct |
1201 ms |
176020 KB |
Output is correct |
10 |
Correct |
520 ms |
180192 KB |
Output is correct |
11 |
Correct |
2420 ms |
177188 KB |
Output is correct |
12 |
Correct |
659 ms |
177352 KB |
Output is correct |
13 |
Correct |
526 ms |
184272 KB |
Output is correct |
14 |
Correct |
1759 ms |
171840 KB |
Output is correct |
15 |
Correct |
1571 ms |
177164 KB |
Output is correct |
16 |
Correct |
2438 ms |
177048 KB |
Output is correct |
17 |
Correct |
676 ms |
184120 KB |
Output is correct |
18 |
Correct |
2687 ms |
177188 KB |
Output is correct |
19 |
Correct |
57 ms |
13512 KB |
Output is correct |
20 |
Correct |
110 ms |
12744 KB |
Output is correct |
21 |
Correct |
150 ms |
12496 KB |
Output is correct |
22 |
Correct |
575 ms |
13256 KB |
Output is correct |
23 |
Correct |
521 ms |
13364 KB |
Output is correct |
24 |
Correct |
104 ms |
13128 KB |
Output is correct |
25 |
Correct |
522 ms |
12616 KB |
Output is correct |
26 |
Correct |
785 ms |
172880 KB |
Output is correct |
27 |
Correct |
1575 ms |
177164 KB |
Output is correct |
28 |
Correct |
1757 ms |
181220 KB |
Output is correct |
29 |
Correct |
1378 ms |
175980 KB |
Output is correct |
30 |
Correct |
2735 ms |
177188 KB |
Output is correct |
31 |
Correct |
2051 ms |
171960 KB |
Output is correct |
32 |
Correct |
2635 ms |
177160 KB |
Output is correct |