제출 #1050718

#제출 시각아이디문제언어결과실행 시간메모리
1050718LucaLucaM팀들 (IOI15_teams)C++17
0 / 100
59 ms16196 KiB
#include "teams.h" #include <vector> #include <algorithm> #include <iostream> const int NMAX = 100 + 7; struct Node { int cnt; Node *l, *r; Node() : cnt(0), l(nullptr), r(nullptr) {} Node(int x) : cnt(x) {} void refresh() { if (l != nullptr && r != nullptr) { cnt = l -> cnt + r -> cnt; } } }; Node* build(int tl, int tr) { if (tl == tr) { return new Node(); } else { int mid = (tl + tr) / 2; Node* ret = new Node(); ret -> l = build(tl, mid); ret -> r = build(mid + 1, tr); return ret; } } Node* update(Node* old, int tl, int tr, int p) { if (tl == tr) { return new Node(1); } else { int mid = (tl + tr) / 2; Node* nw = new Node(); *nw = *old; if (p <= mid) { nw -> l = update(old -> l, tl, mid, p); } else { nw -> r = update(old -> r, mid + 1, tr, p); } nw -> refresh(); return nw; } } int query(const Node *node, int tl, int tr, int ql) { if (ql <= tl) { return node -> cnt; } int mid = (tl + tr) / 2; int ret = 0; if (ql <= mid) { ret += query(node -> l, tl, mid, ql); } ret += query(node -> r, mid + 1, tr, ql); return ret; } int kth(const Node* node, int tl, int tr, int p, int k) { if (node -> cnt < k) { return -1; } if (tl == tr) { return tl; } int mid = (tl + tr) / 2; int st = query(node -> l, tl, mid, p); if (st >= k) { return kth(node -> l, tl, mid, p, k); } else { return kth(node -> r, mid + 1, tr, p, k - st); } } Node* version[NMAX + 1]; std::vector<int> where[NMAX + 1]; int first[NMAX + 1]; // first[p] =def= cel mai mic i a.i. r[i] >= p int n; void init(int N, int A[], int B[]) { n = N; std::vector<std::pair<int, int>> v(n); for (int i = 1; i <= NMAX; i++) { first[i] = -1; } for (int i = 0; i < n; i++) { v[i] = {B[i], A[i]}; } std::sort(v.begin(), v.end()); for (int i = 0; i < n; i++) { auto [r, l] = v[i]; where[l].push_back(i); if (first[r] == -1) { first[r] = i; } } for (int i = n - 1; i >= 0; i--) { if (first[i] == -1) { first[i] = first[i + 1]; } } version[0] = build(0, n - 1); for (int l = 1; l <= n; l++) { version[l] = new Node(); *version[l] = *version[l - 1]; for (const auto &index : where[l]) { version[l] = update(version[l], 0, n - 1, index); } } // std::cout << "skibidiuhhhh: " << query(version[0], 0, n - 1, 0) << '\n'; } int can(int m, int K[]) { std::sort(K, K + m); // std::cout << m << ' ' << K[0] << ' ' << K[1] << '\n'; int p = 0; for (int i = 0; i < m; i++) { p = std::max(p, first[K[i]]); // std::cout << " before " << p << ' ' << K[i] << '\n'; if (p == -1 || p >= n) { return 0; } int q = kth(version[K[i]], 0, n - 1, p, K[i]); // std::cout << " after " << q << ' ' << K[i] << '\n'; if (q == -1) { return 0; } p = q + 1; } 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...