Submission #241584

#TimeUsernameProblemLanguageResultExecution timeMemory
241584dung11112003Jousting tournament (IOI12_tournament)C++11
17 / 100
1081 ms1152 KiB
#include <bits/stdc++.h> #define taskname "" #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define for0(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef long long ll; typedef long double ld; typedef complex <ld> cd; typedef vector <cd> vcd; typedef vector <int> vi; template<class T> using v2d = vector <vector <T> >; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); namespace firstSub { list <int> a; int solve(int n, int m, int val, int *K, int *S, int *E) { int r = 0, p; for0(pos, n) { a.clear(); for0(i, pos) { a.insert(a.end(), K[i]); } a.insert(a.end(), val); for (int i = pos; i < n; i++) { a.insert(a.end(), K[i]); } int cnt = 0; for0(i, m) { auto it = a.begin(); advance(it, S[i]); int winner = 0; bool joined = 0; for (int j = S[i]; j <= E[i]; j++) { uax(winner, *it); joined |= (*it == val); it++; } if (joined) { if (winner == val) { ++cnt; } else { break; } } it = a.begin(); advance(it, S[i]); for (int j = S[i]; j <= E[i]; j++) { if (*it < winner) { it = a.erase(it); } else { it++; } } } if (uax(r, cnt)) { p = pos; } } return p; } } namespace secondSub { const int maxN = 5e3 + 10; int f[maxN * 4], L, R, idx, val; bool lazy[maxN * 4]; void build(int x, int lo, int hi) { if (lo == hi) { f[x] = 1; return; } int mid = (lo + hi) / 2; build(x * 2, lo, mid); build(x * 2 + 1, mid + 1, hi); f[x] = f[x * 2] + f[x * 2 + 1]; } void down(int x) { bool d = lazy[x]; if (d) { lazy[x] = 0; lazy[x * 2] = lazy[x * 2 + 1] = 1; f[x * 2] = f[x * 2 + 1] = 0; } } void update_r(int x, int lo, int hi) { if (lo > R || hi < L) { return; } if (lo >= L && hi <= R) { f[x] = 0; lazy[x] = 1; return; } down(x); int mid = (lo + hi) / 2; update_r(x * 2, lo, mid); update_r(x * 2 + 1, mid + 1, hi); f[x] = f[x * 2] + f[x * 2 + 1]; } void update_p(int x, int lo, int hi) { if (lo == hi && lo == idx) { f[x] = val; return; } int mid = (lo + hi) / 2; if (idx <= mid) { update_p(x * 2, lo, mid); } else { update_p(x * 2 + 1, mid + 1, hi); } f[x] = max(f[x * 2], f[x * 2 + 1]); } int query(int x, int lo, int hi) { if (lo > R || hi < L) { return 0; } if (lo >= L && hi <= R) { return f[x]; } int mid = (lo + hi) / 2; return max(query(x * 2, lo, mid), query(x * 2 + 1, mid + 1, hi)); } int findPos(int x, int lo, int hi, int sum) { if (val <= 0) { return -1; } if (lo == hi) { return lo; } down(x); int mid = (lo + hi) / 2; if (f[x * 2] + sum >= val) { return findPos(x * 2, lo, mid, sum); } return findPos(x * 2 + 1, mid + 1, hi, sum + f[x * 2]); } int solve(int n, int m, int target, int *K, int *S, int *E) { vector <int> l(m), r(m); build(1, 0, n - 1); for0(i, m) { val = E[i] + 1; r[i] = findPos(1, 0, n - 1, 0); val = S[i]; l[i] = findPos(1, 0, n - 1, 0) + 1; L = l[i], R = r[i] - 1; update_r(1, 0, n - 1); } int ans = 0, p; idx = 0, val = target; update_p(1, 0, n - 1); for0(i, n - 1) { idx = i + 1, val = K[i]; update_p(1, 0, n - 1); } for0(pos, n) { int cnt = 0; for0(i, m) { if (l[i] > pos || r[i] < pos) { continue; } L = l[i], R = r[i]; cnt += query(1, 0, n - 1) == target; } if (pos < n - 1) { idx = pos, val = K[pos]; update_p(1, 0, n - 1); idx = pos + 1, val = target; update_p(1, 0, n - 1); } if (uax(ans, cnt)) { p = pos; } } return p; } } namespace fullSub { int solve(int n, int m, int val, int *K, int *S, int *E) { } } int GetBestPosition(int n, int m, int val, int *K, int *S, int *E) { if (n <= 500) { return firstSub::solve(n, m, val, K, S, E); } else if (n <= 5000) { return secondSub::solve(n, m, val, K, S, E); } else { return fullSub::solve(n, m, val, K, S, E); } }

Compilation message (stderr)

tournament.cpp: In function 'int fullSub::solve(int, int, int, int*, int*, int*)':
tournament.cpp:256:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
tournament.cpp: In function 'int secondSub::solve(int, int, int, int*, int*, int*)':
tournament.cpp:247:16: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
         return p;
                ^
tournament.cpp: In function 'int firstSub::solve(int, int, int, int*, int*, int*)':
tournament.cpp:96:16: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
         return p;
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...