이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i)
#define RFOR(i, x, n) for (ll i =x; i>=n; --i)
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;
vector<ll> a;
unordered_map<ll, vector<ll> > pos;
vector<int> X, C, Y;
ll cnt = -1, fir = -1;
bool compare(pii a, pii b) {return a.s < b.s; }
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
vector<pii> dfs(ll layer, ll tot)
{
vector<pii> ret;
ll now = ++cnt;
if (layer==1)
{
ret.pb(mp(mp(now, 0), 2));
if (tot==1) {X[now] = -fir-1; return ret;}
ret.pb(mp(mp(now, 1), 1));
return ret;
}
Y[now] = -cnt-2;
vector<pii> ri = dfs(layer-1, tot);
vector<pii> le;
if (tot - (1LL << (layer-1)) > 0){ X[now] = -cnt-2; le = dfs(layer-1,tot - (1LL << (layer-1)));}
else {X[now] = -fir-1;}
for (ll i=0; i<le.size(); ++i) le[i].s = le[i].s*2 - 1;
for (ll i=0; i<ri.size(); ++i) ri[i].s = ri[i].s*2;
ret.resize(le.size() + ri.size());
merge(all(le), all(ri), ret.begin());
return ret;
}
void build(ll idx)
{
if (pos[idx].size()<=1)
{
C[idx] = (pos[idx].size()?pos[idx][0]:0);
return;
}
ll k = 64 - __builtin_clzll(pos[idx].size()-1);
fir = cnt+1;
C[idx] = -fir-1;
vector<pii> order = dfs(k, pos[idx].size());
sort(all(order), compare);
for (ll i=0; i<pos[idx].size(); ++i)
{
ll key = order[i].f.f, side = order[i].f.s;
if (side) X[key] = pos[idx][i];
else Y[key] = pos[idx][i];
}
}
void create_circuit(int M, std::vector<int> A)
{
ll n = A.size();
C.resize(M+1, 0);
X.resize(2*n, 0); Y.resize(2*n, 0);
a.resize(n);
for (ll i=0; i<n; ++i) a[i] = A[i];
pos[0].pb(a[0]);
for (ll i=0; i<n-1; ++i) pos[A[i]].pb(A[i+1]);
pos[A[n-1]].pb(0);
for (ll i=0; i<=M; ++i) build(i);
X.resize(cnt+1); Y.resize(cnt+1);
answer(C, X, Y);
//show(1);
//for (ll u: C) show(u);
//show(2);
//for (ll u: X) show(u);
//show(3);
//for (ll u: Y) show(u);
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> > dfs(ll, ll)':
doll.cpp:64:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (ll i=0; i<le.size(); ++i) le[i].s = le[i].s*2 - 1;
| ~^~~~~~~~~~
doll.cpp:65:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (ll i=0; i<ri.size(); ++i) ri[i].s = ri[i].s*2;
| ~^~~~~~~~~~
doll.cpp: In function 'void build(ll)':
doll.cpp:84:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (ll i=0; i<pos[idx].size(); ++i)
| ~^~~~~~~~~~~~~~~~
# | 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... |