제출 #765211

#제출 시각아이디문제언어결과실행 시간메모리
765211SanguineChameleon팀들 (IOI15_teams)C++17
21 / 100
4062 ms150600 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std; const int maxN = 5e5 + 20; const int maxL = 20; const int maxM = 2e5 + 20; vector<int> add[maxN]; int tree[maxN * maxL]; int ch[maxN * maxL][2]; int root[maxN * 4]; int dp[maxM]; int node_cnt; int N; int update(int cur_id, int lt, int rt, int pos) { int new_id = ++node_cnt; if (lt == rt) { tree[new_id] = tree[cur_id] + 1; return new_id; } int mt = (lt + rt) / 2; if (pos <= mt) { ch[new_id][0] = update(ch[cur_id][0], lt, mt, pos); ch[new_id][1] = ch[cur_id][1]; } else { ch[new_id][0] = ch[cur_id][0]; ch[new_id][1] = update(ch[cur_id][1], mt + 1, rt, pos); } tree[new_id] = tree[ch[new_id][0]] + tree[ch[new_id][1]]; return new_id; } void init(int _N, int A[], int B[]) { N = _N; for (int i = 0; i < N; i++) { add[B[i]].push_back(A[i]); } for (int i = N; i >= 1; i--) { root[i] = root[i + 1]; for (auto pos: add[i]) { root[i] = update(root[i], 1, N, pos); } } } int get(int id, int lt, int rt, int ql, int qr) { if (lt == ql && rt == qr) { return tree[id]; } int mt = (lt + rt) / 2; if (qr <= mt) { return get(ch[id][0], lt, mt, ql, qr); } else if (ql >= mt + 1) { return get(ch[id][1], mt + 1, rt, ql, qr); } else { return get(ch[id][0], lt, mt, ql, mt) + get(ch[id][1], mt + 1, rt, mt + 1, qr); } } int get(int lx, int rx, int ly) { if (lx > rx) { return 0; } return get(root[ly], 1, N, lx, rx); } priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> events; int can(int M, int K[]) { long long sum = 0; for (int i = 0; i < M; i++) { sum += K[i]; } if (sum > N) { return 0; } set<int> S; while (!events.empty()) { events.pop(); } for (int i = 0; i < M; i++) { events.emplace(K[i], i); } while (!events.empty()) { int id = events.top().second; events.pop(); if (id >= 0) { dp[id] = get(1, K[id], K[id]) - K[id]; for (auto best: S) { dp[id] = min(dp[id], dp[best] + get(K[best] + 1, K[id], K[id]) - K[id]); } if (dp[id] < 0) { return false; } S.insert(id); } else { /* id = -id - 1; auto it = S.find(id); if (it == S.end()) { continue; } if (it != S.begin() && next(it) != S.end()) { int prv = *prev(it); int nxt = *next(it); }*/ } } 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...