답안 #198612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198612 2020-01-26T23:09:47 Z MetB Sails (IOI07_sails) C++14
5 / 100
657 ms 34848 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 n, ll x) {
		int l = 0, r = n - 1;

		while (l < r) {
			int mid = (l + r + 1) / 2;
			if (get (1, 0, start - 1, mid) > x) r = mid - 1;
			else l = mid;
		}

		return l;
	}

	ll upper_bound (ll n, ll x) {
		int l = 0, r = n - 1;

		while (l < r) {
			int mid = (l + r) / 2;
			if (get (1, 0, start - 1, mid) < x) l = mid + 1;
			else r = mid;
		}

		return l;
	}
} 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 (a[i].first, x);
		ll r = t.lower_bound (a[i].first, x);
		assert (l != -1);
		assert (r != -1);
		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 21 ms 31612 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 20 ms 31736 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 26 ms 31736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 32248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 167 ms 32632 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 302 ms 33308 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 561 ms 34532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 596 ms 34808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 657 ms 34848 KB Output isn't correct
2 Halted 0 ms 0 KB -