Submission #390960

#TimeUsernameProblemLanguageResultExecution timeMemory
390960usachevd0Teams (IOI15_teams)C++14
100 / 100
2452 ms259492 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using ld = long double; template<typename T1, typename T2> bool chkmin(T1& x, T2 y) { return y < x ? (x = y, true) : false; } template<typename T1, typename T2> bool chkmax(T1& x, T2 y) { return y > x ? (x = y, true) : false; } void debug_out() { cerr << endl; } template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cerr << ' ' << A; debug_out(B...); } template<typename T> void mdebug_out(T* a, int n) { for (int i = 0; i < n; ++i) { cerr << a[i] << ' '; } cerr << endl; } #ifdef DEBUG #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n) #else #define debug(...) 1337 #define mdebug(a, n) 1337 #endif template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) { for (auto& x : v) { stream << x << ' '; } return stream; } template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) { return stream << p.first << ' ' << p.second; } const int inf32 = 1e9; const int maxN = 5e5 + 5; const int sqrtN = 710; const int maxQ = 2e5 + 5; const int maxS = maxQ; int n; int L[maxN], R[maxN]; namespace persgt { const int maxV = 3e7; int S[maxV], L[maxV], R[maxV]; int V = 1; int newNode() { return V++; } int clone(int v) { if (V >= maxV) { exit(0); } S[V] = S[v]; L[V] = L[v]; R[V] = R[v]; return V++; } int mdf(int v, int vl, int vr, int pos, int delta) { int nv = clone(v); S[nv] += delta; if (vl != vr) { int vm = (vl + vr) >> 1; if (pos <= vm) { L[nv] = mdf(L[nv], vl, vm, pos, delta); } else { R[nv] = mdf(R[nv], vm + 1, vr, pos, delta); } } return nv; } int gt(int v, int vl, int vr, int i) { if (!v || vr < i) { return 0; } if (i <= vl) { return S[v]; } int vm = (vl + vr) >> 1; if (i <= vm) { return gt(L[v], vl, vm, i) + S[R[v]]; } else if (i == vm + 1) { return S[R[v]]; } else { return gt(R[v], vm + 1, vr, i); } } } int ver[maxN]; void init(int _n, int* _L, int* _R) { n = _n; vector<pii> ev; for (int i = 0; i < n; ++i) { L[i] = _L[i]; R[i] = _R[i]; ev.emplace_back(L[i], 0); ev.emplace_back(R[i] + 1, L[i]); } sort(all(ev)); int eptr = 0; int sgt = 0; for (int x = 1; x <= n; ++x) { for (; eptr < ev.size() && ev[eptr].fi == x; ++eptr) { auto& e = ev[eptr]; if (e.se == 0) { sgt = persgt::mdf(sgt, 1, n, x, 1); } else { sgt = persgt::mdf(sgt, 1, n, e.se, -1); } } ver[x] = sgt; } } int count_stu(int x1, int x2) { if (x1 >= x2) { return 0; } int ans = 0; for (int i = 0; i < n; ++i) { ans += x1 < L[i] && L[i] <= x2 && x2 <= R[i]; } return ans; } int count_log(int x1, int x2) { ++x1; chkmax(x1, 1); return persgt::gt(ver[x2], 1, n, x1); } int bx[maxS], bc[maxS]; int dp[maxS]; bool can(int k, int* a) { sort(a, a + k); if (accumulate(a, a + k, 0ll) > n) { return false; } int nk = 0; for (int i = 0; i < k; ++i) { if (nk > 0 && bx[nk - 1] == a[i]) { ++bc[nk - 1]; } else { bx[nk] = a[i]; bc[nk] = 1; ++nk; } } k = nk; // assert(k <= sqrtN); fill(dp, dp + k + 1, inf32); dp[0] = 0; for (int i = 0; i < k; ++i) { dp[i + 1] = count_log(-1, bx[i]) - bx[i] * bc[i]; for (int j = max(0, i - 100); j < i; ++j) { chkmin(dp[i + 1], dp[j + 1] + count_log(bx[j], bx[i]) - bx[i] * bc[i]); } } // mdebug(dp, k + 1); return *min_element(dp, dp + k + 1) >= 0; } #ifdef DEBUG int32_t main() { #ifdef DEBUG freopen("in", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int* L = new int[n]; int* R = new int[n]; for (int i = 0; i < n; ++i) { cin >> L[i] >> R[i]; } init(n, L, R); int Q; cin >> Q; for (int i = 0; i < Q; ++i) { int k; cin >> k; int* a = new int[k]; for (int j = 0; j < k; ++j) { cin >> a[j]; } cout << can(k, a) << '\n'; } return 0; } #endif

Compilation message (stderr)

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:124:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |     for (; eptr < ev.size() && ev[eptr].fi == x; ++eptr) {
      |            ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...