Submission #229601

#TimeUsernameProblemLanguageResultExecution timeMemory
229601maruiiJousting tournament (IOI12_tournament)C++14
100 / 100
82 ms8568 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define ff first #define ss second const int SIZE = 1 << 17; struct ST0 { int A[2 * SIZE]; void update(int x, int v) { for (x += SIZE; x; x >>= 1) A[x] += v; } int query(int s, int e, int v) { int nn = 1, ns = 0, ne = SIZE - 1; while (ns < ne) { int m = ns + ne >> 1; if (m - A[2 * nn] >= v) { nn = 2 * nn; ne = m; } else { v += A[2 * nn]; nn = 2 * nn + 1; ns = m + 1; } } return ns; } } seg0; struct ST1 { int A[2 * SIZE]; void update(int x, int v) { for (x += SIZE; x; x >>= 1) A[x] = max(A[x], v); } int query(int s, int e) { int ret = 0; for (s += SIZE, e += SIZE; s <= e; s >>= 1, e >>= 1) { if ( s & 1) ret = max(ret, A[s++]); if (~e & 1) ret = max(ret, A[e--]); } return ret; } } seg1; struct ST { pii A[2 * SIZE]; int l[2 * SIZE]; void push(int nn, int v) { A[nn].ff += v; l[nn] += v; } void ldown(int nn, int ns, int ne) { push(nn << 1, l[nn]); push(nn << 1 | 1, l[nn]); l[nn] = 0; } void init(int nn, int s, int e) { if (s == e) { A[nn].ss = -s; return; } int m = s + e >> 1; init(nn << 1, s, m); init(nn << 1 | 1, m + 1, e); A[nn] = max(A[nn << 1], A[nn << 1 | 1]); } void update(int nn, int ns, int ne, int s, int e, int v) { if (ns > e || ne < s) return; if (s <= ns && ne <= e) { push(nn, v); return; } int m = ns + ne >> 1; ldown(nn, ns, ne); update(nn << 1, ns, m, s, e, v); update(nn << 1 | 1, m + 1, ne, s, e, v); A[nn] = max(A[nn << 1], A[nn << 1 | 1]); } int query() { return -A[1].ss; } } seg; int L[100001], R[100001], par[100001]; int fnd(int x) { return par[x] == x ? x : par[x] = fnd(par[x]); } void uni(int x, int y) { x = fnd(x), y = fnd(y); if (x == y) return; par[y] = x; seg0.update(max(L[x], L[y]), 1); L[x] = min(L[x], L[y]); R[x] = max(R[x], R[y]); } int GetBestPosition(int N, int C, int R_, int *K, int *S, int *E) { for (int i = 0; i < N; ++i) { seg1.update(i, K[i]); L[i] = R[i] = i; par[i] = i; } seg.init(1, 0, N); for (int i = 0; i < C; ++i) { int s, a; a = s = seg0.query(0, N, S[i]); for (int j = S[i]; j < E[i]; ++j) { int t = R[fnd(s)] + 1; uni(s, t); s = t; } a = fnd(a); if (seg1.query(L[a], R[a] - 1) < R_) seg.update(1, 0, N, L[a], R[a], 1); } return seg.query(); }

Compilation message (stderr)

tournament.cpp: In member function 'int ST0::query(int, int, int)':
tournament.cpp:16:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int m = ns + ne >> 1;
            ~~~^~~~
tournament.cpp: In member function 'void ST::init(int, int, int)':
tournament.cpp:63:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s + e >> 1;
           ~~^~~
tournament.cpp: In member function 'void ST::update(int, int, int, int, int, int)':
tournament.cpp:74:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = ns + ne >> 1;
           ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...