제출 #511455

#제출 시각아이디문제언어결과실행 시간메모리
511455tabr마상시합 토너먼트 (IOI12_tournament)C++17
100 / 100
120 ms10332 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; struct sparse { using T = int; int n, h; vector<vector<T>> table; T func(T x, T y) { return max(x, y); } sparse(const vector<T> &v) { n = (int) v.size(); h = 32 - __builtin_clz(n); table.resize(h); table[0] = v; for (int j = 1; j < h; j++) { table[j].resize(n - (1 << j) + 1); for (int i = 0; i <= n - (1 << j); i++) { table[j][i] = func(table[j - 1][i], table[j - 1][i + (1 << (j - 1))]); } } } T get(int from, int to) { // [from, to] int k = 32 - __builtin_clz(to - from + 1) - 1; return func(table[k][from], table[k][to - (1 << k) + 1]); } }; int GetBestPosition(int n, int c, int r, int k[], int beg[], int end[]) { pbds st; for (int i = 0; i <= n; i++) { st.insert(i); } for (int i = 0; i < c; i++) { beg[i] = *st.find_by_order(beg[i]); end[i] = *st.find_by_order(end[i] + 1); auto it = st.upper_bound(beg[i]); while ((*it) < end[i]) { st.erase(it); it = st.upper_bound(beg[i]); } } vector<int> a(n - 1); for (int i = 0; i < n - 1; i++) { a[i] = k[i]; } sparse sp(a); a = vector<int>(n + 1); for (int i = 0; i < c; i++) { if (sp.get(beg[i], end[i] - 2) < r) { a[beg[i]]++; a[end[i]]--; } } for (int i = 0; i < n; i++) { a[i + 1] += a[i]; } return (int) (max_element(a.begin(), a.end()) - a.begin()); } #ifdef tabr int main() { ios::sync_with_stdio(false); cin.tie(0); int n, c, r, k[100], beg[100], end[100]; cin >> n >> c >> r; for (int i = 0; i < n - 1; i++) { cin >> k[i]; } for (int i = 0; i < c; i++) { cin >> beg[i] >> end[i]; } cout << GetBestPosition(n, c, r, k, beg, end) << '\n'; return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...