#include <bits/stdc++.h>
#include "popa.h"
using namespace std;
int find_root(int l, int r, vector <int> &nxt_l, vector <int> &nxt_r)
{
for (int i = l; i <= r; i++)
if (nxt_l[i] < l && nxt_r[i] > r)
return i;
}
int f(int l, int r, int *left, int *right, vector <int> &nxt_l, vector <int> &nxt_r)
{
if (l > r)
return -1;
int root = find_root(l, r, nxt_l, nxt_r);
left[root] = f(l, root-1, left, right, nxt_l, nxt_r);
right[root] = f(root+1, r, left, right, nxt_l, nxt_r);
return root;
}
int solve(int n, int *left, int *right)
{
vector <int> nxt_l(n), nxt_r(n);
for (int i = 0; i < n; i++)
{
if (i == 0 || query(0, i-1, i, i))
nxt_l[i] = -1;
else
{
int low = 0, high = i-1;
while (low < high)
{
int mid = (low + high + 1) / 2;
if (!query(mid, i-1, i, i))
low = mid;
else
high = mid-1;
}
nxt_l[i] = low;
}
if (i == n-1 || query(i+1, n-1, i, i))
nxt_r[i] = n;
else
{
int low = i+1, high = n-1;
while (low < high)
{
int mid = (low + high) / 2;
if (!query(i+1, mid, i, i))
high = mid;
else
low = mid+1;
}
nxt_r[i] = low;
}
}
return f(0, n-1, left, right, nxt_l, nxt_r);
}
Compilation message
popa.cpp: In function 'int find_root(int, int, std::vector<int>&, std::vector<int>&)':
popa.cpp:11:1: warning: control reaches end of non-void function [-Wreturn-type]
11 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
149 ms |
520 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
364 KB |
too many queries |
2 |
Halted |
0 ms |
0 KB |
- |