이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;
#define sz(v) ((int)v.size())
#define pb push_back
#define pry cout << "YES\n"
#define prn cout << "NO\n"
#define endl '\n'
#define fst first
#define scn second
/* #define ONPC */
const int M = 1e5;
vector<int> v[M+5], x, y, c;
const int S = 4e5;
const int P = 2e7;
vector<int> reala;
map<int,int> compress;
int p = 0;
void answer(vector<int> C, vector<int> X, vector<int> Y);
int
news()
{
x.pb(0);
y.pb(0);
return sz(x);
}
void
dfs2(int l, int r, int s, int k)
{
if (l == r) {
reala[l] = s;
return;
}
int mid = (l+r)>>1;
dfs2(l,mid,s,k+1);
dfs2(mid+1,r,s+(1<<k),k+1);
}
int
dfs(int l, int r, int s, int k, int ind, vector<int>& a)
{
if (k == x[ind-1]) {
if (l > sz(a)-1) {
if (l == (1<<x[ind-1])-1)
return 0;
else
return -ind;
}
return a[compress[reala[l]]];
}
int mid = (l+r)>>1;
int _x = dfs(l,mid,s,k+1,ind,a);
int _y = dfs(mid+1,r,s+(1<<k),k+1,ind,a);
if (_x == _y)
return _x;
int index = news();
p += (1<<(x[ind-1]-k));
x[index-1] = _x;
y[index-1] = _y;
return -index;
}
int
donode(vector<int> &a)
{
if (sz(a)+1 == 1) return a[0];
int l = 31 - __builtin_clz(sz(a)+1);
if (sz(a)+1 != (1<<l))
++l;
int ind = news();
x[ind-1] = l;
p += (1<<(l));
reala.resize(1<<l);
dfs2(0,(1<<l)-1,0,0);
vector<int> normalization;
for (int i = 0; i < sz(a); ++i) {
normalization.pb(reala[i]);
}
sort(normalization.begin(), normalization.end());
for (int i = 0; i < sz(a); ++i) {
compress[normalization[i]] = i;
}
int mid = ((1<<l)-1)>>1;
int _x = dfs(0,mid,0,1,ind,a);
int _y = dfs(mid+1,(1<<l)-1,1,1,ind,a);
x[ind-1] = _x;
y[ind-1] = _y;
return -ind;
}
void
create_circuit(int m, vector<int> a)
{
int n = sz(a);
vector<int> a2;
for (int j = 1; j < n; ++j) {
a2.pb(a[j]);
}
/* a2.pb(0); */
int indx = donode(a2);
c.assign(m+1,indx);
c[0] = a[0];
/* assert(sz(x)<=n*2); */
/* cout << sz(x) << ' ' << n << ' ' << n + 31 - __builtin_clz(n) << endl; */
/* return; */
/* assert(sz(x)<=n+log2(n)); */
/* return; */
/* assert(p<=P); */
answer(c,x,y);
return;
}
#ifdef ONPC
void
answer(vector<int> C, vector<int> X, vector<int> Y)
{
vector<int> ans;
vector<bool> state(sz(X),0);
/* for (int i = 0; i < sz(X); ++i) { */
/* cout << "-" << i+1 << ": " << X[i] << ' ' << Y[i]<< endl; */
/* } */
int tg = C[0];
while (tg) {
if (tg >= 0) {
ans.pb(tg);
tg = C[tg];
} else {
int index = -tg-1;
if (state[index]==0) tg = X[index];
else tg = Y[index];
state[index] = !state[index];
}
}
for (int i = 0; i < sz(X); ++i) {
if (state[i]) {
cout << i << endl;
cout << "Error\n";
return;
}
}
cout << sz(ans) << endl;
for (int i = 0; i < sz(ans); ++i) {
cout << ans[i] << ' ';
}
cout << endl;
return;
}
void
solve()
{
int n, m;
cin >> m;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
cout << m << ' ';
create_circuit(m, a);
}
int32_t
main(int argc, char **argv)
{
if (argc >= 2) {
freopen(argv[1], "r", stdin);
} else
ios_base::sync_with_stdio(0);cin.tie(0);
int t = 1;
/* cin >> t; */
while(t--)
solve();
}
#endif
# | 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... |