Submission #684843

#TimeUsernameProblemLanguageResultExecution timeMemory
684843stevancvJousting tournament (IOI12_tournament)C++14
100 / 100
70 ms6676 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; const int inf = 1e9; int l[N], r[N], ans[N]; struct SegTree { int st[4 * N], lzy[4 * N]; void Init(int node, int l, int r) { st[node] = r; if (l == r) return; int mid = l + r >> 1; Init(2 * node, l, mid); Init(2 * node + 1, mid + 1, r); } void Propagate(int node, int l, int r) { if (lzy[node] == 0) return; if (l < r) { lzy[2 * node] += lzy[node]; lzy[2 * node + 1] += lzy[node]; } st[node] += lzy[node]; lzy[node] = 0; } void Set(int node, int l, int r, int x, int y) { Propagate(node, l, r); if (l == r) { st[node] = y; return; } int mid = l + r >> 1; if (x <= mid) Set(2 * node, l, mid, x, y); else Set(2 * node + 1, mid + 1, r, x, y); st[node] = max(st[2 * node], st[2 * node + 1]); } void Add(int node, int l, int r, int ql, int qr, int x) { Propagate(node, l, r); if (r < ql || qr < l || ql > qr) return; if (ql <= l && r <= qr) { lzy[node] += x; Propagate(node, l, r); return; } int mid = l + r >> 1; Add(2 * node, l, mid, ql, qr, x); Add(2 * node + 1, mid + 1, r, ql, qr, x); st[node] = max(st[2 * node], st[2 * node + 1]); } int Get(int node, int l, int r, int x) { if (l == r) return l; int mid = l + r >> 1; Propagate(2 * node, l, mid); Propagate(2 * node + 1, mid + 1, r); if (st[2 * node] >= x) return Get(2 * node, l, mid, x); return Get(2 * node + 1, mid + 1, r, x); } }seg; vector<int> b; bool Has(int x, int y) { auto it = lower_bound(b.begin(), b.end(), x); if (it == b.end()) return false; return *it < y; } int GetBestPosition(int n, int q, int k, int *p, int *s, int *e) { for (int i = 0; i < n - 1; i++) if (p[i] > k) b.push_back(i); for (int i = 0; i < n; i++) l[i] = r[i] = i; seg.Init(1, 0, n - 1); for (int i = 0; i < q; i++) { int idx = seg.Get(1, 0, n - 1, s[i]); int idy = seg.Get(1, 0, n - 1, e[i]); r[idx] = r[idy]; seg.Add(1, 0, n - 1, l[idx] + 1, n - 1, s[i] - e[i]); if (!Has(l[idx], r[idx])) { ans[l[idx]]++; ans[r[idx] + 1]--; } } int pos = 0; for (int i = 0; i < n; i++) { if (i > 0) ans[i] += ans[i - 1]; if (ans[i] > ans[pos]) pos = i; } return pos; }

Compilation message (stderr)

tournament.cpp: In member function 'void SegTree::Init(int, int, int)':
tournament.cpp:17:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |         int mid = l + r >> 1;
      |                   ~~^~~
tournament.cpp: In member function 'void SegTree::Set(int, int, int, int, int)':
tournament.cpp:36:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int mid = l + r >> 1;
      |                   ~~^~~
tournament.cpp: In member function 'void SegTree::Add(int, int, int, int, int, int)':
tournament.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         int mid = l + r >> 1;
      |                   ~~^~~
tournament.cpp: In member function 'int SegTree::Get(int, int, int, int)':
tournament.cpp:56:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |         int mid = l + r >> 1;
      |                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...