結果
問題 | No.1997 X Lighting |
ユーザー |
![]() |
提出日時 | 2022-07-01 22:28:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 2,040 bytes |
コンパイル時間 | 2,652 ms |
コンパイル使用メモリ | 228,532 KB |
最終ジャッジ日時 | 2025-01-30 03:06:51 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic popusing namespace std;using namespace atcoder;#define rep(i,n) for(int i = 0; i < (int)(n); i++)#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)#define all(x) begin(x), end(x)#define rall(x) rbegin(x), rend(x)template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;} int main() {ios::sync_with_stdio(false);cin.tie(0);ll n;int m;cin >> n >> m;VL us1, us2, vs1, vs2;// u = x + y, v = -x + yrep(i, m) {ll x, y;cin >> x >> y;x--, y--;ll u = x + y, v = -x + y;(u < n ? us1 : us2).emplace_back(u);(v % 2 ? vs1 : vs2).emplace_back(v);}sort(rall(us1)); us1.erase(unique(all(us1)), us1.end());sort(all(us2)); us2.erase(unique(all(us2)), us2.end());sort(all(vs1)); vs1.erase(unique(all(vs1)), vs1.end());sort(all(vs2)); vs2.erase(unique(all(vs2)), vs2.end());ll ans = 0;for(ll u: us1) ans += u + 1;for(ll u: us2) ans += 2 * n - 1 - u;for(ll v: vs1) ans += n - abs(v);for(ll v: vs2) ans += n - abs(v);deque<ll> q1(all(vs1)), q2(all(vs2));for(ll u: us1) {rep(_, 2) {while(!q1.empty() && q1.back() > u) q1.pop_back();while(!q2.empty() && q2.front() < -u) q2.pop_front();swap(q1, q2);}ans -= (int)(u % 2 ? q1 : q2).size();}q1 = deque<ll>(all(vs1)), q2 = deque<ll>(all(vs2));for(ll u: us2) {u = 2 * (n - 1) - u;rep(_, 2) {while(!q1.empty() && q1.back() > u) q1.pop_back();while(!q2.empty() && q2.front() < -u) q2.pop_front();swap(q1, q2);}ans -= (int)(u % 2 ? q1 : q2).size();}cout << ans << '\n';}