제출 #1222016

#제출 시각아이디문제언어결과실행 시간메모리
1222016HappyCapybaraTeams (IOI15_teams)C++20
0 / 100
75 ms56384 KiB
#include "teams.h" #include<bits/stdc++.h> using namespace std; int n; struct node { node *lc, *rc; int val; bool nl, nr; node(node* lcc, node* rcc, int v){ lc = lcc; rc = rcc; val = v; nl = false; nr = false; } }; vector<node*> roots; void build(node* cur, int tl=1, int tr=n){ if (tl == tr) return; int tm = (tl+tr)/2; cur->lc = new node(nullptr, nullptr, 0); cur->rc = new node(nullptr, nullptr, 0); build(cur->lc, tl, tm); build(cur->rc, tm+1, tr); } void update(node* cur, int pos, int tl=1, int tr=n){ if (tl == tr){ cur->val++; return; } int tm = (tl+tr)/2; if (pos <= tm){ if (!cur->nl){ cur->lc = new node(cur->lc->lc, cur->lc->rc, cur->lc->val); cur->nl = true; } update(cur->lc, pos, tl, tm); } else { if (!cur->nr){ cur->rc = new node(cur->rc->lc, cur->rc->rc, cur->rc->val); cur->nr = true; } update(cur->rc, pos, tl, tr); } cur->val = cur->lc->val+cur->rc->val; } int query(node* cur, int l, int r, int tl=1, int tr=n){ if (l > r) return 0; if (r < tl || tr < l) return 0; if (l <= tl && tr <= r) return cur->val; int tm = (tl+tr)/2; int res = 0; if (l <= tm) res += query(cur->lc, l, r, tl, tm); if (tm+1 <= r) res += query(cur->rc, l, r, tm+1, tr); return res; } void init(int N, int A[], int B[]){ n = N; roots.push_back(new node(nullptr, nullptr, 0)); build(roots.back()); vector<vector<int>> ev(N+1); for (int i=0; i<N; i++) ev[A[i]].push_back(B[i]); for (int i=1; i<=N; i++){ roots.push_back(new node(roots.back()->lc, roots.back()->rc, roots.back()->val)); for (int x : ev[i]) update(roots.back(), x); } /*for (int i=1; i<=N; i++){ for (int j=i; j<=N; j++) cout << query(roots[i], j, N) << " "; cout << endl; }*/ } int can(int M, int K[]){ sort(K, K+M); vector<int> ch; for (int i=0; i<M; i++){ if (i == M-1 || K[i] != K[i+1]) ch.push_back(K[i]); } int q = ch.size(); ch.push_back(n+1); vector<int> occ(q, 0); //cout << endl; for (int i=0; i<M; i++){ //cout << K[i] << endl; int req = K[i]; for (int j=0; j<q; j++){ if (ch[j] < K[i]) continue; int rem = query(roots[K[i]], ch[j], ch[j+1]-1)-occ[j]; //cout << rem << endl; if (rem > req){ occ[j] += req; req = 0; } else { req -= rem; occ[j] += rem; } if (!req) break; } //cout << req << endl; if (req) 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...