結果

問題 No.1965 Heavier
ユーザー umimelumimel
提出日時 2022-06-03 22:23:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 349 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 173,504 KB
実行使用メモリ 25,240 KB
最終ジャッジ日時 2023-10-21 02:01:36
合計ジャッジ時間 6,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 161 ms
6,496 KB
testcase_07 AC 165 ms
6,496 KB
testcase_08 AC 345 ms
25,240 KB
testcase_09 AC 183 ms
6,496 KB
testcase_10 AC 182 ms
6,496 KB
testcase_11 AC 182 ms
6,496 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 169 ms
6,496 KB
testcase_16 AC 168 ms
6,496 KB
testcase_17 AC 111 ms
5,440 KB
testcase_18 AC 164 ms
6,496 KB
testcase_19 AC 155 ms
6,232 KB
testcase_20 AC 161 ms
6,496 KB
testcase_21 AC 146 ms
6,232 KB
testcase_22 AC 145 ms
5,968 KB
testcase_23 AC 101 ms
5,176 KB
testcase_24 AC 127 ms
5,704 KB
testcase_25 AC 341 ms
25,240 KB
testcase_26 AC 349 ms
25,240 KB
testcase_27 AC 173 ms
6,496 KB
testcase_28 AC 172 ms
6,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll N_MAX = 2e5;

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll ans = 0;
    multiset<ll> p, m;
    for(ll l=0, r=0; l<n-1; l++){
        if(l == r){
            p.insert(a[l]+b[l]);
            m.insert(a[l]-b[l]);
            r++;
        }

        if(r < n){
            while(p.lower_bound(a[r]+b[r])==p.end() && m.lower_bound(a[r]-b[r])==m.end()){
                p.insert(a[r]+b[r]);
                m.insert(a[r]-b[r]);
                r++;
                if(r == n) break;
            }
        }
        
        ans += (r-l-1);
        p.erase(p.lower_bound(a[l]+b[l]));
        m.erase(m.lower_bound(a[l]-b[l]));
    }

    cout << ans << endl;
}
0