답안 #198610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198610 2020-01-26T23:03:03 Z MetB Sails (IOI07_sails) C++14
5 / 100
295 ms 34808 KB
#include <bits/stdc++.h>
 
#define N 1000001
 
using namespace std;
 
typedef long long ll;
 
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

struct V {
	ll min, max, midl, midr;
	V () {
		min = max = midl = midr = INF;
	}

	V (ll x) {
		min = max = midl = midr = x;
	}

	V (ll a, ll b, ll c, ll d) : min (a), max (b), 
		midl (c), midr (d) {}
};

struct LazySeg {
	V t[N];
	ll ta[N], start;
	V merge (V a, V b) {
		return V (a.min, b.max, a.max, b.min);
	}

	void push (ll node) {
		t[node].min += ta[node];
		t[node].max += ta[node];
		t[node].midl += ta[node];
		t[node].midr += ta[node];
		if (node < start) {
			ta[2 * node] += ta[node];
			ta[2 * node + 1] += ta[node];
		}
		ta[node] = 0;
	}

	void build (ll n) {
		start = 1;
		while (start < n) start <<= 1;

		for (ll i = 0; i < n; i++)
			t[start + i] = V (0);

		for (ll i = start - 1; i > 0; i--)
			t[i] = merge (t[2 * i], t[2 * i + 1]);
	}

	void update (ll node, ll tl, ll tr, ll l, ll r, ll d) {
		push (node);
		if (r < tl || tr < l) return;
		if (l <= tl && tr <= r) {
			ta[node] += d;
			push (node);
			return;
		}

		ll tm = (tl + tr) / 2;
		update (2 * node, tl, tm, l, r, d);
		update (2 * node + 1, tm + 1, tr, l, r, d);
		t[node] = merge (t[2 * node], t[2 * node + 1]);
	}

	ll get (ll node, ll tl, ll tr, ll x) {
		push (node);
		if (tl == tr) return t[node].min;
		ll tm = (tl + tr) / 2;
		if (x <= tm) return get (2 * node, tl, tm, x);
		else return get (2 * node + 1, tm + 1, tr, x);
	}

	ll lower_bound (ll node, ll tl, ll tr, ll n, ll x) {
		push (node);
		if (n <= tl) return -1;
		if (tr < n) {
			if (t[node].min > x) return -1;
			while (node < start) {
				push (node);
				if (t[node].midr > x) node *= 2;
				else node = 2 * node + 1;
			}
			return node - start;
		}

		int tm = (tl + tr) / 2;
		int r = lower_bound (2 * node + 1, tm + 1, tr, n, x);
		if (r != -1) return r;
		else return lower_bound (2 * node, tl, tm, n, x);
	}

	ll upper_bound (ll node, ll tl, ll tr, ll n, ll x) {
		push (node);
		if (n <= tl) return -1;
		if (tr < n) {
			if (t[node].max < x) return -1;
			while (node < start) {
				push (node);
				if (t[node].midl < x) node = 2 * node + 1;
				else node *= 2;
			}
			return node - start;
		}

		int tm = (tl + tr) / 2;
		int l = upper_bound (2 * node, tl, tm, n, x);
		if (l != -1) return l;
		else return upper_bound (2 * node + 1, tm + 1, tr, n, x);
	}
} t;

ll n, m;
pair <ll, ll> a[N];

int main () {
	cin >> n;

	for (ll i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		m = max (m, a[i].first);
	}
	t.build (m);

	sort (a, a + n);

	for (ll i = n - 1; i >= 0; i--) {
		if (!a[i].second) continue;
		ll x = t.get (1, 0, t.start - 1, a[i].second - 1);
		ll l = t.upper_bound (1, 0, t.start - 1, a[i].first, x);
		ll r = t.lower_bound (1, 0, t.start - 1, a[i].first, x);
		if (l) t.update (1, 0, t.start - 1, 0, l - 1, 1);
		a[i].second -= l;
		t.update (1, 0, t.start - 1, r - a[i].second + 1, r, 1);
	}

	ll sum = 0;

	for (ll i = 0; i < m; i++) {
		ll x = t.get (1, 0, t.start - 1, i);
		sum += x * (x - 1) / 2;
	}

	cout << sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 31608 KB Output is correct
2 Correct 20 ms 31608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 31608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 31608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 31608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 31736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 32248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 32632 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 150 ms 33400 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 260 ms 34456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 258 ms 34692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 295 ms 34808 KB Output isn't correct
2 Halted 0 ms 0 KB -