結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-27 18:52:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,043 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 85,340 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-28 12:00:17
合計ジャッジ時間 4,926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 28 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 49 ms
5,376 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;


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

	ll ans = 0;
	V<set<ll> > naname1(2, set<ll>({}));
	V<set<ll> > naname2(2, set<ll>({}));
	rep(i, 0, m) {
		ll x, y;	cin >> x >> y;
		x--;	y--;
		ll p = x - y, q = x + y;
		int b = q & 1;
		if (naname1[b].find(p) == naname1[b].end()) {
			ans += min(n - 1 + p, n - 1) - max(p, (ll)0) + 1;
			auto itr1 = naname2[b].lower_bound(max(p, -p));
			auto itr2 = naname2[b].upper_bound(min(2 * (n - 1) - p, 2 * (n - 1) + p));
			ans -= distance(itr1, itr2);
			naname1[b].insert(p);
		}
		if (naname2[b].find(q) == naname2[b].end()) {
			ans += min(q, n - 1) - max(-n + 1 + q, (ll)0) + 1;
			auto itr1 = naname1[b].lower_bound(max(-q, q - 2 * (n - 1)));
			auto itr2 = naname1[b].upper_bound(min(2 * (n - 1) - q, q));
			ans -= distance(itr1, itr2);
			naname2[b].insert(q);
		}
	}
	cout << ans << endl;

	return 0;
}
0