Submission #229601

# Submission time Handle Problem Language Result Execution time Memory
229601 2020-05-05T09:34:32 Z maruii Jousting tournament (IOI12_tournament) C++14
100 / 100
82 ms 8568 KB
#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

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 time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 7 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2560 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2560 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 10 ms 2688 KB Output is correct
3 Correct 7 ms 2688 KB Output is correct
4 Correct 9 ms 2688 KB Output is correct
5 Correct 9 ms 2688 KB Output is correct
6 Correct 8 ms 2688 KB Output is correct
7 Correct 9 ms 2816 KB Output is correct
8 Correct 9 ms 2816 KB Output is correct
9 Correct 7 ms 2688 KB Output is correct
10 Correct 9 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 4864 KB Output is correct
2 Correct 73 ms 6700 KB Output is correct
3 Correct 31 ms 6392 KB Output is correct
4 Correct 81 ms 8568 KB Output is correct
5 Correct 76 ms 8312 KB Output is correct
6 Correct 82 ms 8312 KB Output is correct
7 Correct 81 ms 8568 KB Output is correct
8 Correct 78 ms 8440 KB Output is correct
9 Correct 26 ms 6144 KB Output is correct
10 Correct 30 ms 7168 KB Output is correct