이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 200005;
#include "doll.h"
int sm[2*MAXN], add[2*MAXN], nxt[MAXN];
vi gr[MAXN];
vi C, X, Y;
void create_circuit(int M, vector<int> A) {
for (int i = 1; i < (int) A.size(); ++i) {
gr[A[i-1]].push_back(A[i]);
}
gr[A.back()].push_back(0);
C.resize(M+1);
C[0] = A[0];
for (int i = 1; i <= M; ++i) {
if (gr[i].empty()) {
C[i] = 0;
continue;
}
if (gr[i].size() == 1) {
C[i] = gr[i][0];
continue;
}
int n = 2;
while (n < (int)gr[i].size())
n<<=1;
int extra = n-(int)gr[i].size();
int fSw = X.size(); // first new switch
C[i] = -fSw-1;
sm[1] = 0;
add[1] = 1;
for (int j = 1; j < n; ++j) {
sm[j<<1] = sm[j];
sm[j<<1|1] = sm[j]+add[j];
add[j<<1] = add[j<<1|1] = add[j]<<1;
}
for (int j = 0, erased = 0; j < n; ++j) {
if (sm[n+j] < extra) {
erased++;
} else {
nxt[sm[n+j]] = gr[i][j-erased];
}
}
sm[fSw] = 0;
add[fSw] = n>>1;
X.emplace_back(), Y.emplace_back();
for (int s = fSw; s < (int) X.size(); ++s) {
if (add[s] == 1) {
X[s] = sm[s] < extra? -fSw-1 : nxt[sm[s]];
Y[s] = nxt[sm[s]+1];
continue;
}
if (sm[s]+add[s] <= extra) {
X[s] = -fSw-1;
} else {
X[s] = -X.size()-1;
sm[X.size()] = sm[s];
add[X.size()] = add[s]>>1;
X.emplace_back(), Y.emplace_back();
}
Y[s] = -X.size()-1;
sm[X.size()] = sm[s]+add[s];
add[X.size()] = add[s]>>1;
X.emplace_back(), Y.emplace_back();
}
}
// for (int i = 0; i <= M; ++i) {
// cerr << C[i] << ' ';
// }
// cerr << endl;
// for (int i = 0; i < (int) X.size(); ++i) {
// cerr << X[i] << ' ' << Y[i] << endl;
// }
answer(C, X, Y);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |