結果

問題 No.230 Splarraay スプラレェーイ
ユーザー sugim48sugim48
提出日時 2015-06-19 23:38:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,352 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 83,616 KB
実行使用メモリ 4,580 KB
最終ジャッジ日時 2023-09-21 10:19:01
合計ジャッジ時間 3,153 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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> sumr(N + 1), sumb(N + 1);
	vector<unko> v;
	int R = 0, B = 0;
	for (int q = 0; q < Q; q++) {
		if (q % 300 == 0) {
			vector<int> a(N);
			for (int i = 0; i < v.size(); i++)
				for (int j = v[i].l; j < v[i].r; j++)
					a[j] = v[i].c;
			v.clear();
			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