結果
| 問題 | No.1997 X Lighting | 
| コンテスト | |
| ユーザー |  MasKoaTS | 
| 提出日時 | 2022-03-27 20:37:30 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 658 ms / 2,000 ms | 
| コード長 | 1,518 bytes | 
| コンパイル時間 | 1,294 ms | 
| コンパイル使用メモリ | 90,228 KB | 
| 最終ジャッジ日時 | 2025-01-28 13:07:54 | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#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;
}
            
            
            
        