結果

問題 No.1074 増殖
ユーザー ats5515ats5515
提出日時 2020-06-05 22:42:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 152,176 KB
実行使用メモリ 8,392 KB
最終ジャッジ日時 2023-08-22 16:34:26
合計ジャッジ時間 3,817 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 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,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 26 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 19 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
int INF = 1 << 30;
struct Solver {
	set<pair<int, int> > st;

	Solver() {
		st.emplace(INF, 0);
		st.emplace(0, INF);
	}

	int query(int x, int y) {
		int res = 0;
		auto ptr = st.lower_bound({x, -INF});
		if ((*ptr).second < y) {
			while (true) {
				--ptr;
				if ((*ptr).second <= y) {
					--ptr;
					int x1 = (*ptr).first;
					++ptr;
					int x2 = (*ptr).first;

					int y1 = (*ptr).second;
					++ptr;
					int y2 = (*ptr).second;
					res -= (x2 - x1) * (y1 - y2);

					--ptr;
					ptr = st.erase(ptr);
				} else {
					break;
				}
			}
			{
				int x1 = (*ptr).first;
				++ptr;
				int y2 = (*ptr).second;
				res += (x - x1) * (y - y2);
				st.emplace(make_pair(x, y));
			}
		}
		return res;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int X[2];
	int Y[2];
	Solver solver[4];
	for (int i = 0; i < N; i++) {
		cin >> X[0] >> Y[0] >> X[1] >> Y[1];
		int res = 0;
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				res += solver[j * 2 + k].query(abs(X[j]), abs(Y[k]));
			}
		}
		cout << res << "\n";
	}
	return 0;
}
0