結果

問題 No.1074 増殖
ユーザー QCFiumQCFium
提出日時 2020-06-05 21:59:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 172,444 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-22 15:24:32
合計ジャッジ時間 2,657 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct Stairs {
	std::set<std::pair<int, int> > all;
	Stairs () {
		all.insert({-1000000000, 1000000000});
		all.insert({1000000000, -1000000000});
	}
	
	int add(int x, int y) {
		auto itr = all.lower_bound({x, y});
		if (*itr == std::pair<int, int>{x, y}) return 0;
		auto added = [&] (std::set<std::pair<int, int> >::iterator itr) {
			int res = itr->first * itr->second;
			if (std::prev(itr)->first > 0) res -= std::prev(itr)->first * itr->second;
			if (std::next(itr)->second > 0) res -= std::next(itr)->second * itr->first;
			if (std::prev(itr)->first > 0 && std::next(itr)->second > 0) res += std::prev(itr)->first * std::next(itr)->second;
			return res;
		};
		int res = 0;
		if (itr->second >= y) return 0;
		while (std::prev(itr)->second <= y) res -= added(std::prev(itr)), all.erase(std::prev(itr));
		return added(all.insert({x, y}).first) + res;
	}
};

int main() {
	int n = ri();
	Stairs all[4] = { Stairs() };
	for (int i = 0; i < n; i++) {
		int x0 = ri(), y0 = ri();
		int x1 = ri(), y1 = ri();
		int res = all[0].add(x1, y1) + all[1].add(-x0, y1) + all[2].add(x1, -y0) + all[3].add(-x0, -y0);
		printf("%d\n", res);
	}
	return 0;
}
 
0