# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
365497 |
2021-02-11T18:19:48 Z |
tfg |
popa (BOI18_popa) |
C++17 |
|
135 ms |
556 KB |
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include "popa.h"
#include <stack>
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
// query(a, b, c, d) gcd[a, b] == gcd[c, d]
const int ms = 1010;
int liml[ms], limr[ms];
int solve(int l, int r, int* Left, int* Right) {
if(l >= r) {
return -1;
}
for(int i = l; i < r; i++) {
if(liml[i] <= l && r <= limr[i]) {
Left[i] = solve(l, i, Left, Right);
Right[i] = solve(i+1, r, Left, Right);
return i;
}
}
assert(0);
}
//int query(int a, int b, int c, int d);
int solve(int n, int *l, int *r) {
for(int i = 0; i < n; i++) {
l[i] = r[i] = -1;
}
std::vector<int> st;
for(int i = 0; i < n; i++) {
while(!st.empty() && query(st.back(), st.back(), st.back(), i) == 0) {
// [st.back(), i] isn't good for st.back
limr[st.back()] = i;
st.pop_back();
}
liml[i] = st.empty() ? 0 : st.back() + 1;
st.push_back(i);
}
assert(!st.empty());
for(auto val : st) {
limr[val] = n;
}
return solve(0, n, l, r);
}
/*int values[ms];
int ansL[ms], ansR[ms];
int query(int l, int r) {
int ans = 0;
for(int i = l; i <= r; i++) {
int x = values[i];
while(x != 0) {
ans %= x;
std::swap(ans, x);
}
}
std::cout << "query(" << l << ", " << r << ") = " << ans << '\n';
return ans;
}
int query(int a, int b, int c, int d) {
int ans = query(a, b) == query(c, d);
std::cout << "query(" << a << ", " << b << ", " << c << ", " << d << ") = " << ans << '\n';
return ans;
}
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
int n;
std::cin >> n;
for(int i = 0; i < n; i++) {
std::cin >> values[i];
}
std::cout << solve(n, ansL, ansR) << '\n';
for(int i = 0; i < n; i++) {
std::cout << ansL[i] << ", " << ansR[i] << "\n";
}
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
512 KB |
Output is correct |
2 |
Correct |
12 ms |
364 KB |
Output is correct |
3 |
Correct |
10 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
368 KB |
Output is correct |
2 |
Correct |
97 ms |
364 KB |
Output is correct |
3 |
Correct |
76 ms |
396 KB |
Output is correct |
4 |
Correct |
101 ms |
480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
364 KB |
Output is correct |
2 |
Correct |
135 ms |
364 KB |
Output is correct |
3 |
Correct |
52 ms |
556 KB |
Output is correct |
4 |
Correct |
111 ms |
488 KB |
Output is correct |