제출 #289445

#제출 시각아이디문제언어결과실행 시간메모리
289445_7_7_팀들 (IOI15_teams)C++14
21 / 100
4101 ms379384 KiB
#include "teams.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; //#define int long long //#pragma GCC optimize("Ofast") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") #define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout); #define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define all(x) x.begin(), x.end() #define sz(s) (int)s.size() #define pb push_back #define ppb pop_back #define mp make_pair #define s second #define f first typedef pair < long long, long long > pll; typedef pair < int, int > pii; typedef unsigned long long ull; typedef vector < pii > vpii; typedef vector < int > vi; typedef long double ldb; typedef long long ll; typedef double db; typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set; const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 5e5 + 12; const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}, block = 450; const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9); const db eps = 1e-12, pi = acos(-1); const ll INF = 1e18; int n; struct node { node *l, *r; int sum; node () { l = r = NULL; sum = 0; } node (int x) { sum = x; l = r = NULL; } node (node *L, node *R) { l = L, r = R; sum = (!l ? 0 : l->sum) + (!r ? 0 : r->sum); } }; typedef node * pnode; pnode root[N]; pnode build (int tl = 0, int tr = n - 1) { if (tl == tr) return new node(); int tm = (tl + tr) >> 1; return new node(build(tl, tm), build(tm + 1, tr)); } pnode update (pnode t, int pos, int x, int tl = 1, int tr = n) { if (tl == tr) return new node(t->sum + x); int tm = (tl + tr) >> 1; if (pos <= tm) return new node(update(t->l, pos, x, tl, tm), t->r); return new node(t->l, update(t->r, pos, x, tm + 1, tr)); } int get (pnode t, int l, int r, int tl = 1, int tr = n) { if (l > r || l > tr || tl > r) return 0; if (l <= tl && tr <= r) return t->sum; int tm = (tl + tr) >> 1; return get(t->l, l, r, tl, tm) + get(t->r, l, r, tm + 1, tr); } vi g[N]; int cnt[N]; void init(int _n, int a[], int b[]) { n = _n; for (int i = 0; i < n; ++i) g[a[i]].pb(b[i]); root[0] = build(); for (int i = 1; i <= n; ++i) { root[i] = root[i - 1]; for (auto j : g[i]) root[i] = update(root[i], j, 1); } } int can(int m, int k[]) { int sum = 0; vpii vv; vi vals; for (int i = 0; i < m; ++i) { sum += k[i]; if (sum > n) return 0; vals.pb(k[i]); } sort(all(vals)); for (int i = 0; i < sz(vals); ) { int j = i, s = 0; while (j < sz(vals) && vals[i] == vals[j]) s += vals[j++]; vv.pb(mp(vals[i], s)); i = j; } if (m > block) { priority_queue < int, vi, less < int > > q; int j = 0; for (auto x : vv) { while (j <= x.f) { for (auto b : g[j]) q.push(b); ++j; } while (sz(q) && x.s) { if (q.top() >= x.f) --x.s; q.pop(); } if (x.s) return 0; } return 1; } for (int i = 0; i < sz(vv); ++i) cnt[i] = 0; for (int i = 0; i < sz(vv); ++i) { int rest = vv[i].s; for (int j = i; j < sz(vv); ++j) { int cur = get(root[vv[i].f], vv[j].f, (j == sz(vv) - 1 ? n : vv[j + 1].f - 1)) - cnt[j]; // cerr << i << ' ' << cur << ' ' << vv[j].f << ' ' << (j == sz(vv) - 1 ? n : vv[j + 1].f - 1) << ' ' << cnt[j] << endl; cnt[j] += min(cur, rest); rest -= min(cur, rest); if (!rest) break; } if (rest) return 0; } return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...