結果
| 問題 | No.1997 X Lighting |
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2022-03-28 12:53:51 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 639 ms / 2,000 ms |
| コード長 | 1,389 bytes |
| 記録 | |
| コンパイル時間 | 1,220 ms |
| コンパイル使用メモリ | 88,032 KB |
| 最終ジャッジ日時 | 2025-01-28 13:10:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / 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> 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;
}
MasKoaTS