Submission #800418

#TimeUsernameProblemLanguageResultExecution timeMemory
800418errayTeams (IOI15_teams)C++17
0 / 100
825 ms524288 KiB
#include "teams.h" #include<bits/stdc++.h> using namespace std; #ifdef DEBUG #include "/home/ioi/codes/ioi15_d1/debug.h" #else #define debug(...) void(37) #endif template<typename T> vector<T> inverse_fuck(T* a, int N) { vector<T> res(N); for (int i = 0; i < N; ++i) { res[i] = a[i]; } return res; } namespace PST { struct node { node* l = NULL; node* r = NULL; int sum = 0; }; node* modify(node* prev, int l, int r, int p) { debug(l, r); node* v = new node(); if (prev != NULL) { v->l = prev->l; v->r = prev->r; v->sum = prev->sum; } v->sum += 1; if (l < r) { int mid = (l + r) >> 1; if (p <= mid) { v->l = modify(v->l, l, mid, p); } else { v->r = modify(v->r, mid + 1, r, p); } } return v; } int get(node* v, int l, int r, int ll) { if (v == NULL) { return 0; } if (l >= ll) { return v->sum; } int mid = (l + r) >> 1; int res = 0; if (ll <= mid) { res += get(v->l, l, mid, ll); } res += get(v->r, mid + 1, r, ll); return res; } //whatever void get_synced(node* v, int l, int r, int ll, int rr, vector<int>& vec, vector<int>& res) { int mid = (l + r) >> 1; int split_l = int(lower_bound(vec.begin() + ll, vec.begin() + rr + 1, mid) - vec.begin()); int split_r = split_l; while (split_r < rr && vec[split_r] == mid) { ++split_r; } debug(l, r, vec, ll, rr, split_l, split_r); if (v->r != NULL) { int& sum = v->r->sum; res[l] += sum; res[split_r] -= sum; if (split_r <= rr) { get_synced(v->r, mid + 1, r, split_r, rr, vec, res); } } if (ll < split_l) { get_synced(v->l, l, mid, ll, split_l - 1, vec, res); } } } struct SegTree { int n; vector<PST::node*> roots; SegTree(int _n) : n(_n) { roots.resize(1); roots[0] = new PST::node(); } SegTree() { } PST::node* modify(int x) { roots.push_back(PST::modify(roots.back(), 0, n - 1, x)); return roots.back(); } int get(PST::node* v, int ll) { return PST::get(v, 0, n - 1, ll); } vector<int> get_synced(PST::node* v, vector<int>& vec, int l) { int r = int(vec.size()) - 1; if (l > r) { return vector<int>{}; } vector<int> res(r - l + 2); debug(vec, l, r); PST::get_synced(v, 0, n - 1, l, r, vec, res); return res; } }; int N; vector<array<int, 2>> A; SegTree st; vector<PST::node*> vers; vector<int> pt; void init(int __N, int __A[], int __B[]) { N = __N; auto L = inverse_fuck(__A, N); auto R = inverse_fuck(__B, N); debug(N, L, R); A.resize(N); for (int i = 0; i < N; ++i) { A[i] = array<int, 2>{L[i], R[i]}; } sort(A.begin(), A.end()); debug(A); st = SegTree(N + 3); for (int i = 0; i < N; ++i) { debug(i); auto v = st.modify(A[i][1]); if (i == N - 1|| A[i + 1][0] != A[i][0]) { pt.push_back(A[i][0]); vers.push_back(v); } } } int can(int M, int __K[]) { auto K = inverse_fuck(__K, M); sort(K.begin(), K.end()); if (accumulate(K.begin(), K.end(), 0LL) > N) { return false; } debug(M, K); vector<int> comp, sz; for (int i = 0; i < M; ++i) { if (i == 0 || comp.back() != K[i]) { comp.push_back(K[i]); sz.push_back(0); } sz.back() += K[i]; } auto Contains = [&](int l, int r) { return (l == -1 ? 0 : st.get(vers[l], r)); }; int s = int(comp.size()); vector<int> from(s); int p = -1; debug(comp, from); vector<int> dp(s); for (int i = 0; i < s; ++i) { while (p + 1 < int(pt.size()) && pt[p + 1] <= comp[i]) { ++p; } int x = comp[i]; dp[i] += Contains(p, x) - sz[i]; debug(i, dp[i]); int sync = s - i - 1; debug(p, (p != -1 ? pt[p] : -1)); vector<int> cost = (p == -1 ? vector<int>(sync, 0) : st.get_synced(vers[p], comp, i + 1)); debug(cost); for (int j = 1; j < sync; ++j) { cost[j] += cost[j - 1]; } debug(cost); for (int j = i + 1; j < s; ++j) { dp[j] = min(dp[j], dp[i] - cost[j - i - 1]); } if (dp[i] < 0) { return false; } } return true; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...