#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define sp " "
//#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define LOGN 18
vector<pair<vector<int>, int>> curr[100005];
int arr[100005], n;
void init(int N, int D, int H[]) {
n = N;
for (int i = 0; i < N; i++)
arr[i] = H[i];
}
void curseChanges(int U, int A[], int B[]) {
for (int i = 0; i < U; i++)
{
int a = A[i], b = B[i];
vector<int> x, y;
int flag = 0;
if (!curr[a].empty())
{
for (auto j : curr[a].back().st)
{
if (j == b) flag = 1;
else x.pb(j);
}
}
if (flag == 0) x.pb(b);
if (!curr[b].empty())
{
for (auto j : curr[b].back().st)
{
if (j == a) flag = 1;
else y.pb(j);
}
}
if (flag == 0) y.pb(a);
curr[a].pb({x, i});
curr[b].pb({y, i});
}
}
int question(int x, int y, int v) {
int a = 0, b = 0;
if (curr[x].empty() || curr[y].empty()) return 1e9;
for (int i = LOGN; i >= 0; i--)
{
int tmp1 = a + (1<<i), tmp2 = b + (1<<i);
if (tmp1 < curr[x].size() && curr[x][tmp1].nd < v) a = tmp1;
if (tmp2 < curr[y].size() && curr[y][tmp2].nd < v) b = tmp2;
}
if (curr[x][a].nd >= v || curr[y][b].nd >= v) return 1e9;
int i = 0, j = 0;
int ans = 1e9;
vector<int> k, l;
for (auto i : curr[x][a].st) k.pb(arr[i]);
for (auto i : curr[y][b].st) l.pb(arr[i]);
sort(k.begin(), k.end());
sort(l.begin(), l.end());
while(i < k.size() && j < l.size())
{
ans = min(ans, abs(k[i] - l[j]));
if (k[i] < l[j]) i++;
else j++;
}
return ans;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if (tmp1 < curr[x].size() && curr[x][tmp1].nd < v) a = tmp1;
| ~~~~~^~~~~~~~~~~~~~~~
potion.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if (tmp2 < curr[y].size() && curr[y][tmp2].nd < v) b = tmp2;
| ~~~~~^~~~~~~~~~~~~~~~
potion.cpp:68:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while(i < k.size() && j < l.size())
| ~~^~~~~~~~~~
potion.cpp:68:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while(i < k.size() && j < l.size())
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2768 KB |
Output is correct |
2 |
Correct |
2 ms |
2768 KB |
Output is correct |
3 |
Correct |
3 ms |
2768 KB |
Output is correct |
4 |
Correct |
13 ms |
3528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
35680 KB |
Output is correct |
2 |
Correct |
284 ms |
35656 KB |
Output is correct |
3 |
Correct |
242 ms |
38324 KB |
Output is correct |
4 |
Correct |
1318 ms |
222924 KB |
Output is correct |
5 |
Correct |
414 ms |
62016 KB |
Output is correct |
6 |
Runtime error |
472 ms |
262144 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
278 ms |
35576 KB |
Output is correct |
2 |
Runtime error |
418 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
4428 KB |
Output is correct |
2 |
Correct |
56 ms |
4688 KB |
Output is correct |
3 |
Correct |
84 ms |
4688 KB |
Output is correct |
4 |
Correct |
541 ms |
9168 KB |
Output is correct |
5 |
Correct |
516 ms |
8000 KB |
Output is correct |
6 |
Correct |
74 ms |
4816 KB |
Output is correct |
7 |
Correct |
436 ms |
8448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2768 KB |
Output is correct |
3 |
Correct |
2 ms |
2768 KB |
Output is correct |
4 |
Correct |
3 ms |
2768 KB |
Output is correct |
5 |
Correct |
13 ms |
3528 KB |
Output is correct |
6 |
Correct |
283 ms |
35680 KB |
Output is correct |
7 |
Correct |
284 ms |
35656 KB |
Output is correct |
8 |
Correct |
242 ms |
38324 KB |
Output is correct |
9 |
Correct |
1318 ms |
222924 KB |
Output is correct |
10 |
Correct |
414 ms |
62016 KB |
Output is correct |
11 |
Runtime error |
472 ms |
262144 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |