# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
647102 |
2022-10-01T15:06:59 Z |
georgievskiy |
popa (BOI18_popa) |
C++14 |
|
705 ms |
444 KB |
//#define LOCAL
#ifndef LOCAL
#include "popa.h"
#endif
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
int ARR[100], LEFT[100], RIGHT[100];
int f_gcd(int a, int b) {
int g = 0;
for (int i = a; i <= b; i++)
g = __gcd(g, ARR[i]);
return g;
}
int query(int a, int b, int c, int d) {
return f_gcd(a, b) == f_gcd(c, d);
}
#endif
int rec(int l, int r, int* left, int* right, vector<int>& dl, vector<int>& dr) {
if (l >= r)
return -1;
if (l + 1 == r)
return l;
int root = -1;
for (int i = l; i < r; i++) {
if (dl[i] <= l && dr[i] >= r - 1) {
root = i;
break;
}
}
assert(root >= l && root < r);
left[root] = rec(l, root, left, right, dl, dr);
right[root] = rec(root + 1, r, left, right, dl, dr);
return root;
}
int solve(int n, int* left, int* right) {
fill(left, left + n, -1), fill(right, right + n, -1);
vector<int> dl(n), dr(n);
for (int i = 0; i < n; i++) {
{
int l = -1, r = i;
while (r - l > 1) {
int c = (l + r) / 2;
if (query(c, i, i, i))
r = c;
else
l = c;
}
dl[i] = r;
}
{
int l = i, r = n;
while (r - l > 1) {
int c = (l + r) / 2;
if (query(i, c, i, i))
l = c;
else
r = c;
}
dr[i] = l;
}
}
return rec(0, n, left, right, dl, dr);
}
#ifdef LOCAL
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> ARR[i];
solve(n, LEFT, RIGHT);
for (int i = 0; i < n; i++)
cout << LEFT[i] << " ";
cout << "\n";
for (int i = 0; i < n; i++)
cout << RIGHT[i] << " ";
cout << "\n";
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
208 KB |
Output is correct |
2 |
Correct |
35 ms |
208 KB |
Output is correct |
3 |
Correct |
47 ms |
208 KB |
Output is correct |
4 |
Correct |
49 ms |
284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
636 ms |
424 KB |
Output is correct |
2 |
Correct |
673 ms |
424 KB |
Output is correct |
3 |
Correct |
377 ms |
372 KB |
Output is correct |
4 |
Correct |
705 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
208 KB |
too many queries |
2 |
Halted |
0 ms |
0 KB |
- |