結果

問題 No.230 Splarraay スプラレェーイ
ユーザー sugim48sugim48
提出日時 2015-06-19 23:46:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 336 ms / 5,000 ms
コード長 2,385 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 83,488 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-21 10:20:51
合計ジャッジ時間 3,203 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 59 ms
4,380 KB
testcase_10 AC 39 ms
4,500 KB
testcase_11 AC 29 ms
4,376 KB
testcase_12 AC 59 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 172 ms
4,380 KB
testcase_15 AC 184 ms
4,384 KB
testcase_16 AC 186 ms
4,384 KB
testcase_17 AC 191 ms
4,376 KB
testcase_18 AC 336 ms
4,396 KB
testcase_19 AC 108 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct unko {
	int c, l, r;
	unko(int _c, int _l, int _r) {
		c = _c; l = _l; r = _r;
	}
};

i_i f(int N, vector<int>& sumr, vector<int>& sumb, vector<unko>& v, int l, int r) {
	i_i p;
	for (int i = 0; i < v.size(); i++) {
		int _l = max(v[i].l, l), _r = min(v[i].r, r);
		if (_l >= _r) continue;
		if (v[i].c == 0) {
			p.first += sumr[_r] - sumr[_l];
			p.second += sumb[_r] - sumb[_l];
		}
		if (v[i].c == 1) p.first += _r - _l;
		if (v[i].c == 2) p.second += _r - _l;
	}
	return p;
}

int main() {
	int N, Q; cin >> N >> Q;
	vector<int> a(N), sumr(N + 1), sumb(N + 1);
	vector<unko> v;
	ll R = 0, B = 0;
	for (int q = 0; q < Q; q++) {
		if (q % 300 == 0) {
			for (int i = 0; i < v.size(); i++)
				for (int j = v[i].l; j < v[i].r; j++)
					if (v[i].c)
						a[j] = v[i].c;
			v.clear();
			v.push_back(unko(0, 0, N));
			for (int j = 1; j <= N; j++) {
				sumr[j] = sumr[j - 1];
				sumb[j] = sumb[j - 1];
				if (a[j - 1] == 1) sumr[j]++;
				if (a[j - 1] == 2) sumb[j]++;
			}
		}
		int x, l, r; scanf("%d%d%d", &x, &l, &r);
		r++;
		if (x == 0) {
			i_i p = f(N, sumr, sumb, v, l, r);
			if (p.first > p.second) R += p.first;
			if (p.first < p.second) B += p.second;
		}
		else {
			vector<unko> _v;
			for (int i = 0; i < v.size(); i++) {
				if (l <= v[i].l && v[i].r <= r) continue;
				if (v[i].l < l && r < v[i].r) {
					_v.push_back(unko(v[i].c, v[i].l, l));
					_v.push_back(unko(v[i].c, r, v[i].r));
				}
				else if (v[i].l < l)
					_v.push_back(unko(v[i].c, v[i].l, min(v[i].r, l)));
				else if (r < v[i].r)
					_v.push_back(unko(v[i].c, max(v[i].l, r), v[i].r));
			}
			_v.push_back(unko(x, l, r));
			v = _v;
		}
	}
	i_i p = f(N, sumr, sumb, v, 0, N);
	R += p.first;
	B += p.second;
	cout << R << ' ' << B << endl;
}
0