結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-28 12:53:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 91,084 KB
実行使用メモリ 20,304 KB
最終ジャッジ日時 2024-04-28 12:00:32
合計ジャッジ時間 6,041 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 36 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 62 ms
8,704 KB
testcase_14 AC 205 ms
20,132 KB
testcase_15 AC 54 ms
7,936 KB
testcase_16 AC 75 ms
9,600 KB
testcase_17 AC 229 ms
17,192 KB
testcase_18 AC 114 ms
11,120 KB
testcase_19 AC 276 ms
19,520 KB
testcase_20 AC 333 ms
20,304 KB
testcase_21 AC 328 ms
20,068 KB
testcase_22 AC 291 ms
19,556 KB
testcase_23 AC 155 ms
12,104 KB
testcase_24 AC 6 ms
6,944 KB
testcase_25 AC 321 ms
19,360 KB
testcase_26 AC 255 ms
17,436 KB
testcase_27 AC 272 ms
17,548 KB
testcase_28 AC 66 ms
8,192 KB
testcase_29 AC 63 ms
8,192 KB
testcase_30 AC 289 ms
19,024 KB
testcase_31 AC 184 ms
13,952 KB
testcase_32 AC 38 ms
6,948 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> xv(2, V<ll>({}));
	VV<ll> yv(2, V<ll>({}));
	itrep(itr, st1) {
		ll x = *itr;
		xv[abs(x) & 1].push_back(x);
	}
	itrep(itr, st2) {
		ll y = *itr;
		yv[abs(y) & 1].push_back(y);
	}

	ll num = 0, dc = 0;
	itrep(itr, st1) {
		ll x = *itr;	int b = abs(x) & 1;
		num += min(x, n - 1) - max(-n + 1 + x, (ll)0) + 1;
		auto itr1 = lower_bound(all(yv[b]), max(-x, x - 2 * (n - 1)));
		auto itr2 = upper_bound(all(yv[b]), min(2 * (n - 1) - x, x));
		dc += itr2 - itr1;
	}
	itrep(itr, st2) {
		ll y = *itr;	int b = abs(y) & 1;
		num += min(n - 1 + y, n - 1) - max(y, (ll)0) + 1;
		auto itr1 = lower_bound(all(xv[b]), max(y, -y));
		auto itr2 = upper_bound(all(xv[b]), min(2 * (n - 1) - y, 2 * (n - 1) + y));
		dc += itr2 - itr1;
	}

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

	return 0;
}
0