제출 #96431

#제출 시각아이디문제언어결과실행 시간메모리
96431someone_aa자동 인형 (IOI18_doll)C++17
100 / 100
152 ms11688 KiB
#include <bits/stdc++.h> #include "doll.h" #define pb push_back using namespace std; const int maxn = 300100; int n, m; int N, br; // N is the first power of two greater than n int x[maxn], y[maxn]; int build_tree(int l, int r, int cnt) { int ind = br; br++; if(r == l + 1) { //cout<<l<<", "<<r<<" - "<<cnt<<"\n"; if(cnt == 1) x[ind] = 1; return ind; } //cout<<l<<" "<<r<<" -> "<<ind<<" "<<cnt<<"\n"; int tsize = r - l + 1; int mid = tsize / 2; if(cnt <= mid) { // build recursively right subtree // make left subtree go left int midpoint = (l+r)/2; x[ind] = 1; y[ind] = build_tree(midpoint+1, r, cnt); } else { // make all in right // everything that is left put in left subtree int midpoint = (l+r)/2; y[ind] = build_tree(midpoint+1, r, mid); x[ind] = build_tree(l, midpoint, cnt-mid); } return ind; } bool state[maxn]; int pntr_x[maxn]; int pntr_y[maxn]; void insert_point(int ind, int val, int l, int r) { if(r == l + 1) { // base case if(!state[ind]) { state[ind] = true; if(x[ind] == 0) { pntr_x[ind] = val; } else insert_point(x[ind], val, 0, N-1); } else { state[ind] = false; if(y[ind] == 0) { pntr_y[ind] = val; } else insert_point(y[ind], val, 0, N-1); } return; } else { state[ind] = !state[ind]; int mid = (l + r) / 2; if(state[ind]) { // left if(x[ind] == 1) insert_point(x[ind], val, 0, N-1); else insert_point(x[ind], val, l, mid); } else { // right if(y[ind] == -1) insert_point(y[ind], val, 0, N-1); else insert_point(y[ind], val, mid+1, r); } } } void create_circuit(int M, std::vector<int> A) { A.pb(0); m = M; n = A.size(); vector<int>C(M+1); for(int i=0;i<=M;i++) { C[i] = -1; } N = 1; while(N < n) { N *= 2; } br = 1; build_tree(0, N-1, n); vector<int>X, Y; for(int i=0;i<n;i++) { insert_point(1, A[i], 0, N-1); } for(int i=1;i<br;i++) { if(x[i] == 0) X.pb(pntr_x[i]); else X.pb(-x[i]); if(y[i] == 0) Y.pb(pntr_y[i]); else Y.pb(-y[i]); } answer(C, X, Y); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...