結果

問題 No.1997 X Lighting
ユーザー asaringoasaringo
提出日時 2022-07-02 17:13:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 2,116 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 213,248 KB
実行使用メモリ 18,364 KB
最終ジャッジ日時 2023-08-18 08:28:49
合計ジャッジ時間 8,757 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 19 ms
4,644 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 32 ms
5,124 KB
testcase_14 AC 134 ms
18,132 KB
testcase_15 AC 45 ms
7,264 KB
testcase_16 AC 64 ms
8,680 KB
testcase_17 AC 173 ms
15,568 KB
testcase_18 AC 85 ms
10,264 KB
testcase_19 AC 208 ms
17,596 KB
testcase_20 AC 224 ms
18,300 KB
testcase_21 AC 246 ms
18,364 KB
testcase_22 AC 229 ms
17,432 KB
testcase_23 AC 99 ms
11,224 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 214 ms
17,732 KB
testcase_26 AC 179 ms
15,708 KB
testcase_27 AC 193 ms
15,796 KB
testcase_28 AC 50 ms
7,500 KB
testcase_29 AC 46 ms
7,464 KB
testcase_30 AC 219 ms
17,608 KB
testcase_31 AC 125 ms
12,832 KB
testcase_32 AC 28 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
#define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr);
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

ll n , m ;
ll X[101010] , Y[101010] ;
map<ll,bool> mp_p , mp_n ;
vector<ll> odd , eve ;
vector<int> vec ;

int main(){
    fast_input_output
    cin >> n >> m ;
    n-- ;
    ll res = 0 ;
    rep(i,m) {
        ll x , y ;
        cin >> x >> y ;
        x-- ; y-- ;
        X[i] = x ;
        Y[i] = y ;
        // pos
        if(!mp_p[y-x]){
            res += n - abs(y-x) + 1 ;
            mp_p[y-x] = true ;
            if((y+x)%2==0) eve.push_back(y-x) ;
            if((y+x)%2==1) odd.push_back(y-x) ;
        }
        if(!mp_n[y+x]){
            vec.push_back(i) ;
            mp_n[y+x] = true ;
        }
    }
    sort(eve.begin(),eve.end()) ;
    sort(odd.begin(),odd.end()) ;
    for(int i : vec){
        ll x = X[i] , y = Y[i] ;
        ll cnt = min(x+y,2*n-x-y) + 1 ;
        if((x+y)%2==0){
            if(x+y<n){
                ll sum = upper_bound(eve.begin(),eve.end(),x+y) - lower_bound(eve.begin(),eve.end(),-x-y) ;
                res += cnt - sum ;
            }
            else{
                ll sum = upper_bound(eve.begin(),eve.end(),-x-y+2*n) - lower_bound(eve.begin(),eve.end(),x+y-2*n) ;
                res += cnt - sum ;
            }
        }
        if((x+y)%2==1){
            if(x+y<n){
                ll sum = upper_bound(odd.begin(),odd.end(),x+y) - lower_bound(odd.begin(),odd.end(),-x-y) ;
                res += cnt - sum ;
            }
            else{
                ll sum = upper_bound(odd.begin(),odd.end(),-x-y+2*n) - lower_bound(odd.begin(),odd.end(),x+y-2*n) ;
                res += cnt - sum ;
            }
        }
    }
    cout << res << endl ;
}
0