Submission #93821

# Submission time Handle Problem Language Result Execution time Memory
93821 2019-01-11T19:09:33 Z Noam527 Weighting stones (IZhO11_stones) C++17
100 / 100
47 ms 4500 KB
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
using namespace std;

void debug(string names) {
	cout << '\n';
}
template<typename A1, typename... A2>
void debug(string names, A1 par, A2... left) {
	int pos = 0;
	for (; pos < names.size() && names[pos] != ' ' && names[pos] != ','; pos++)
		cout << names[pos];
	cout << ": " << par << "  ";
	while (pos < names.size() && (names[pos] == ' ' || names[pos] == ',')) {
		pos++;
	}
	names.erase(names.begin(), names.begin() + pos);
	debug(names, left...);
}

struct segtree {
	int n;
	vector<int> tag, mn, mx;
	segtree() {}
	segtree(int sz) {
		n = sz + 1;
		while (n != (n&-n)) n += (n&-n);
		tag.resize(2 * n, 0);
		mn.resize(2 * n, 0);
		mx.resize(2 * n, 0);
	}
	void fix(int x) {
		if (x >= n) return;
		mn[x] = tag[x] + min(mn[2 * x + 1], mn[2 * x + 2]);
		mx[x] = tag[x] + max(mx[2 * x + 1], mx[2 * x + 2]);
	}
	void push(int x) {
		if (x >= n) return;
		for (auto i : { x + x + 1, x + x + 2 }) {
			tag[i] += tag[x];
			mn[i] += tag[x];
			mx[i] += tag[x];
		}
		tag[x] = 0;
	}
	void add(int pos, int val) {
		upd(pos, n - 1, val, 0, 0, n - 1);
	}
	void upd(int l, int r, int val, int node, int nl, int nr) {
		if (nr < l || r < nl) return;
		if (l <= nl && nr <= r) {
			tag[node] += val;
			mn[node] += val;
			mx[node] += val;
			return;
		}
		int mid = (nl + nr) / 2;
		upd(l, r, val, 2 * node + 1, nl, mid);
		upd(l, r, val, 2 * node + 2, mid + 1, nr);
		fix(node);
	}
	int m() {
		return mn[0];
	}
	int M() {
		return mx[0];
	}
};

int n, p[2];

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	segtree T(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> p[0] >> p[1];
		p[1] = 2 * p[1] - 3;
		sum += p[1];
		T.add(p[0], p[1]);
		if (T.m() == sum) cout << ">\n";
		else if (T.M() == sum) cout << "<\n";
		else cout << "?\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 5 ms 888 KB Output is correct
11 Correct 29 ms 2424 KB Output is correct
12 Correct 47 ms 4344 KB Output is correct
13 Correct 43 ms 4376 KB Output is correct
14 Correct 42 ms 4408 KB Output is correct
15 Correct 43 ms 4400 KB Output is correct
16 Correct 43 ms 4472 KB Output is correct
17 Correct 45 ms 4500 KB Output is correct
18 Correct 44 ms 4476 KB Output is correct
19 Correct 46 ms 4476 KB Output is correct
20 Correct 43 ms 4344 KB Output is correct
21 Correct 43 ms 4472 KB Output is correct
22 Correct 43 ms 4344 KB Output is correct
23 Correct 43 ms 4344 KB Output is correct
24 Correct 44 ms 4344 KB Output is correct
25 Correct 46 ms 4460 KB Output is correct