이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "popa.h"
#include <bits/stdc++.h>
using namespace std;
bool is_anc(int x, int y){
// gcd(S_x, S_x) == gcd(S_x, S_{x+1}) => S_x | S_{x+1} => x+1 is an ancestor
return query(x, x, x, y);
}
int solve(int n, int* left, int* right){
for(int i = 0; i < n; i += 1) left[i] = right[i] = -1;
vector<int> down_right;
down_right.push_back(0);
int cur = 1;
while(cur < n){
while(cur < n and !is_anc(down_right.back(), cur)){
down_right.push_back(cur);
cur += 1;
}
if(cur == n) break;
int more_down = down_right.back(); down_right.pop_back();
while(down_right.size() > 0 and is_anc(down_right.back(), cur)){
right[down_right.back()] = more_down;
more_down = down_right.back(); down_right.pop_back();
}
left[cur] = more_down;
down_right.push_back(cur);
cur += 1;
}
int more_down = down_right.back(); down_right.pop_back();
while(down_right.size() > 0){
right[down_right.back()] = more_down;
more_down = down_right.back(); down_right.pop_back();
}
return more_down;
}
/*
signed main(){
int n; cin >> n;
int left[n];
int right[n];
solve(n, left, right);
for(int i = 0; i < n; i += 1) cout << left[i] << " " << right[i] << endl;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |