제출 #726889

#제출 시각아이디문제언어결과실행 시간메모리
726889Alex_tz307팀들 (IOI15_teams)C++17
0 / 100
4050 ms389436 KiB
#include <bits/stdc++.h> #include "teams.h" using namespace std; struct node { int sum; node* l; node* r; node() : sum(0), l(nullptr), r(nullptr) {} }; const int kN = 5e5; int n, ver[1 + kN]; node *roots[1 + kN]; vector<int> dr[1 + kN]; void build(node *root, int lx, int rx) { if (lx == rx) { return; } int mid = (lx + rx) / 2; root->l = new node; build(root->l, lx, mid); root->r = new node; build(root->r, mid + 1, rx); } void update(node *prev, node *curr, int lx, int rx, int pos) { if (lx == rx) { curr->sum = prev->sum + 1; return; } int mid = (lx + rx) / 2; if (pos <= mid) { curr->l = new node; curr->r = prev->r; update(prev->l, curr->l, lx, mid, pos); } else { curr->l = prev->l; curr->r = new node; update(prev->r, curr->r, mid + 1, rx, pos); } curr->sum = curr->l->sum + curr->r->sum; } int query(node *root, int lx, int rx, int st, int dr) { if (st <= lx && rx <= dr) { return root->sum; } int mid = (lx + rx) / 2; int sum = 0; if (st <= mid) { sum += query(root->l, lx, mid, st, dr); } if (mid < dr) { sum += query(root->r, mid + 1, rx, st, dr); } return sum; } void init(int N, int A[], int B[]) { n = N; for (int i = 0; i < N; ++i) { dr[A[i]].emplace_back(B[i]); } roots[0] = new node; build(roots[0], 1, n); int version = 0; for (int l = 1; l <= n; ++l) { for (const int &r : dr[l]) { version += 1; roots[version] = new node; update(roots[version - 1], roots[version], 1, n, r); } ver[l] = version; } } int can(int m, int a[]) { int sum = 0; for (int i = 0; i < m; ++i) { sum += a[i]; if (n < sum) { return 0; } } sort(a, a + m); vector<pair<int, int>> ranges; int last = a[0]; for (int i = 1; i < m; ++i) { if (last != a[i]) { ranges.emplace_back(last, a[i] - 1); } last = a[i]; } ranges.emplace_back(last, n); vector<int> used(ranges.size()); int ptr = 0; for (int i = 0; i < m; ++i) { int j = i; while (j < m && a[i] == a[j]) { j += 1; } int req = a[i] * (j - i); for (int k = ptr; k < (int)ranges.size(); ++k) { int l, r; tie(l, r) = ranges[k]; int take = min(req, query(roots[ver[a[i]]], 1, n, l, r) - used[k]); req -= take; used[k] += take; } if (req) { return 0; } j = i - 1; ptr += 1; } return 1; }

컴파일 시 표준 에러 (stderr) 메시지

teams.cpp: In function 'int query(node*, int, int, int, int)':
teams.cpp:54:51: warning: declaration of 'dr' shadows a global declaration [-Wshadow]
   54 | int query(node *root, int lx, int rx, int st, int dr) {
      |                                               ~~~~^~
teams.cpp:17:13: note: shadowed declaration is here
   17 | vector<int> dr[1 + kN];
      |             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...