結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-27 20:37:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 1,518 bytes
コンパイル時間 1,078 ms
コンパイル使用メモリ 93,056 KB
実行使用メモリ 20,264 KB
最終ジャッジ日時 2024-04-28 12:00:26
合計ジャッジ時間 8,933 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 7 ms
6,940 KB
testcase_06 AC 43 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 6 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 74 ms
8,704 KB
testcase_14 AC 282 ms
20,264 KB
testcase_15 AC 82 ms
7,808 KB
testcase_16 AC 125 ms
9,472 KB
testcase_17 AC 402 ms
17,396 KB
testcase_18 AC 179 ms
11,136 KB
testcase_19 AC 495 ms
19,476 KB
testcase_20 AC 559 ms
20,048 KB
testcase_21 AC 546 ms
20,072 KB
testcase_22 AC 495 ms
19,836 KB
testcase_23 AC 189 ms
12,032 KB
testcase_24 AC 7 ms
6,940 KB
testcase_25 AC 521 ms
19,360 KB
testcase_26 AC 414 ms
17,228 KB
testcase_27 AC 453 ms
17,536 KB
testcase_28 AC 110 ms
8,064 KB
testcase_29 AC 100 ms
7,936 KB
testcase_30 AC 522 ms
19,184 KB
testcase_31 AC 266 ms
13,952 KB
testcase_32 AC 54 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define itrep(itr, st) for(auto itr = st.begin(); itr != st.end(); itr++)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;


int main(void) {
	ll n, m;	cin >> n >> m;

	VV<ll> p(m, V<ll>(2));
	set<ll> st1 = {}, st2 = {};
	rep(i, 0, m) {
		ll x, y;	cin >> x >> y;
		x--;	y--;
		p[i][0] = x - y;
		p[i][1] = x + y;
		st1.insert(p[i][0]);
		st2.insert(p[i][1]);
	}
	
	VV<ll> naname1(2, V<ll>({}));
	VV<ll> naname2(2, V<ll>({}));
	itrep(itr, st1) {
		ll x = *itr;
		naname1[abs(x) & 1].push_back(x);
	}
	itrep(itr, st2) {
		ll y = *itr;
		naname2[y & 1].push_back(y);
	}

	ll num = 0, dc = 0;
	st1 = {};	st2 = {};
	rep(i, 0, m) {
		ll x = p[i][0], y = p[i][1];
		int b = y & 1;
		if (st1.find(x) == st1.end()) {
			num += min(n - 1 + x, n - 1) - max(x, (ll)0) + 1;
			auto itr1 = lower_bound(all(naname2[b]), max(x, -x));
			auto itr2 = upper_bound(all(naname2[b]), min(2 * (n - 1) - x, 2 * (n - 1) + x));
			dc += itr2 - itr1;
			st1.insert(x);
		}
		if (st2.find(y) == st2.end()) {
			num += min(y, n - 1) - max(-n + 1 + y, (ll)0) + 1;
			auto itr1 = lower_bound(all(naname1[b]), max(-y, y - 2 * (n - 1)));
			auto itr2 = upper_bound(all(naname1[b]), min(2 * (n - 1) - y, y));
			dc += itr2 - itr1;
			st2.insert(y);
		}
	}

	ll ans = num - dc / 2;
	cout << ans << endl;

	return 0;
}
0