이 제출은 이전 버전의 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];
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 logg = 0;
while ((1<<logg) < (int)gr[i].size())
logg++;
// cerr << i << ": " << logg << endl;
int fSw = X.size(); // first new switch
X.resize((int) X.size()+(1<<logg)-1);
Y.resize((int) Y.size()+(1<<logg)-1);
C[i] = -fSw-1;
gr[i].insert(gr[i].begin(), (1<<logg)-(int)gr[i].size(), -fSw-1);
sm[1] = 0;
add[1] = 1;
int n = 1<<(logg-1);
--fSw;
for (int j = 1; j < n; ++j) {
X[fSw+j] = -fSw-(j<<1)-1;
Y[fSw+j] = -fSw-(j<<1|1)-1;
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; j < n; ++j) {
// cerr << j << ": " << add[n+j] << " " << sm[n+j] << endl;
X[n+fSw+j] = gr[i][sm[n+j]];
Y[n+fSw+j] = gr[i][sm[n+j]+add[n+j]];
}
}
// 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... |