제출 #765192

#제출 시각아이디문제언어결과실행 시간메모리
765192SanguineChameleon팀들 (IOI15_teams)C++17
34 / 100
4070 ms178620 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; const int lim = 0; vector<pair<int, int>> qadd[maxN]; vector<pair<int, int>> qrem[maxN]; int tree[maxN * maxL]; int ch[maxN * maxL][2]; int root[maxN * 4]; int dp[maxM]; int cnt[maxN]; 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++) { qadd[A[i]].emplace_back(B[i], i); qrem[B[i]].emplace_back(B[i], i); } for (int i = N; i >= 1; i--) { root[i] = root[i + 1]; for (auto p: qrem[i]) { root[i] = update(root[i], 1, N, A[p.second]); } } } 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); } 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; } if (M > lim) { set<pair<int, int>> S; bool ok = true; for (int i = 0; i < M; i++) { cnt[K[i]] += K[i]; } for (int i = 1; i <= N; i++) { for (auto p: qadd[i]) { S.insert(p); } if ((int)S.size() < cnt[i]) { ok = false; break; } for (int j = 0; j < cnt[i]; j++) { S.erase(S.begin()); } for (auto p: qrem[i]) { S.erase(p); } } for (int i = 0; i < M; i++) { cnt[K[i]] -= K[i]; } return ok; } else { sort(K, K + M); for (int i = 0; i < M; i++) { dp[i] = get(1, K[i], K[i]) - K[i]; for (int j = 0; j < i; j++) { dp[i] = min(dp[i], dp[j] + get(K[j] + 1, K[i], K[i]) - K[i]); } 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...