Submission #800392

#TimeUsernameProblemLanguageResultExecution timeMemory
800392errayTeams (IOI15_teams)C++17
77 / 100
4069 ms331624 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; } int ll = -1; 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) { if (l >= ll) { return v->sum; } int mid = (l + r) >> 1; int res = 0; if (ll <= mid) { res += (v->l == NULL ? 0 : get(v->l, l, mid)); res += (v->r != NULL ? v->r->sum : 0); } else if (v->r != NULL) { res += get(v->r, mid + 1, r); } return 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) { return PST::get(v, 0, n - 1); } }; 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 + 1); 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<array<int, 2>> comp; for (int i = 0; i < M; ++i) { if (i == 0 || comp.back()[0] != K[i]) { comp.push_back({K[i], 0}); //overflow on sums } comp.back()[1] += K[i]; } auto Contains = [&](int l, int r) { ll = r; return (l == -1 ? 0 : st.get(vers[l])); }; int s = int(comp.size()); vector<int> from(s); int p = -1; for (int i = 0; i < s; ++i) { while (p + 1 < int(pt.size()) && pt[p + 1] <= comp[i][0]) { ++p; } from[i] = p; } debug(comp, from); vector<int> dp(s); for (int i = 0; i < s; ++i) { auto[x, sz] = comp[i]; dp[i] = 0; for (int j = 0; j < i; ++j) { dp[i] = min(dp[i], dp[j] - Contains(from[j], x)); } dp[i] += Contains(from[i], x) - sz; 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...