Submission #606553

#TimeUsernameProblemLanguageResultExecution timeMemory
6065538e7Teams (IOI15_teams)C++17
77 / 100
666 ms403828 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r){ while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 1000005 #define pii pair<int, int> #define ff first #define ss second #define int ll #include "teams.h" struct segtree{ vector<int> seg[4*maxn]; void build(int cur, int l, int r, vector<pii> a) { if (r <= l || a.size() == 0) return; if (r - l == 1) { for (auto p:a) seg[cur].push_back(p.ss); sort(seg[cur].begin(), seg[cur].end()); return; } int m = (l + r) / 2; vector<pii> lef, rig; for (auto p:a) { if (p.ff < m)lef.push_back(p); else rig.push_back(p); } build(cur*2, l, m, lef), build(cur*2+1, m, r, rig); int ls = seg[cur*2].size(), rs = seg[cur*2+1].size(); vector<int> &le = seg[cur*2], &ri = seg[cur*2+1]; int ind = 0; for (int i = 0;i < ls;i++) { while (ind < rs && ri[ind] < le[i]) seg[cur].push_back(ri[ind++]); seg[cur].push_back(le[i]); } while (ind < rs) seg[cur].push_back(ri[ind++]); } int query(int cur, int l, int r, int ql, int qr) { //number of segments covering [ql, qr] if (r <= l || l > ql) return 0; if (r-1 <= ql) { int ind = lower_bound(seg[cur].begin(), seg[cur].end(), qr) - seg[cur].begin(); return (int)seg[cur].size() - ind; } int m = (l + r) / 2; return query(cur*2, l, m, ql, qr) + query(cur*2+1, m, r, ql, qr); } } tr; int v[maxn]; int n; void init(signed N, signed A[], signed B[]) { n = N; vector<pii> a(n); for (int i = 0;i < n;i++) { a[i] = {A[i], B[i]}; v[A[i]]++; v[B[i] + 1]--; } tr.build(1, 1, N+1, a); for (int i = 1;i <= n;i++) v[i] += v[i-1]; //number of segments covering i } signed can(signed m, signed num[]) { sort(num, num + m); vector<int> c(m, 0), dp(m, 0); int tot = 0; for (int i = 0;i < m;i++) { tot += num[i]; c[i] = v[num[i]] - num[i]; dp[i] = c[i]; if (c[i] < 0 || tot > n) return 0; } vector<int> stk; auto f = [&] (int l, int r){ return c[r] + dp[l] - tr.query(1, 1, n+1, num[l], num[r]); }; for (int i = 0;i < m;i++) { while (stk.size() > 1 && f(stk.back(), i) > f(stk[stk.size()-2], i)) stk.pop_back(); if (stk.size()) { dp[i] = min(dp[i], f(stk.back(), i)); if (dp[i] < 0) return 0; } stk.push_back(i); } return 1; } /* 4 2 3 1 1 3 4 4 4 1 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...