結果

問題 No.1965 Heavier
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-15 22:56:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 2,304 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 120,252 KB
実行使用メモリ 17,560 KB
最終ジャッジ日時 2023-08-20 21:41:15
合計ジャッジ時間 7,860 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 214 ms
17,432 KB
testcase_07 AC 216 ms
17,500 KB
testcase_08 AC 210 ms
17,444 KB
testcase_09 AC 281 ms
17,496 KB
testcase_10 AC 280 ms
17,384 KB
testcase_11 AC 280 ms
17,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 256 ms
17,560 KB
testcase_16 AC 258 ms
17,444 KB
testcase_17 AC 165 ms
15,708 KB
testcase_18 AC 233 ms
17,504 KB
testcase_19 AC 226 ms
17,228 KB
testcase_20 AC 235 ms
17,456 KB
testcase_21 AC 212 ms
16,952 KB
testcase_22 AC 209 ms
16,664 KB
testcase_23 AC 132 ms
10,980 KB
testcase_24 AC 170 ms
16,108 KB
testcase_25 AC 215 ms
17,392 KB
testcase_26 AC 207 ms
17,432 KB
testcase_27 AC 227 ms
17,492 KB
testcase_28 AC 229 ms
17,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

template<class S, S (*op)(S, S), S (*e)()>struct SegTree {
    vector<S> seg;
    long long N = 1;

    SegTree (long long n) : SegTree(vector<S>(n, e())) {}
    SegTree (const vector<S> &v){
        long long n = v.size();
        while (N < n) N *= 2;
        seg.resize(N*2-1, e());
        for (long long i=0; i<n; i++) seg[i+N-1] = v[i];
        for (long long i=N-2; i>=0; i--){
            seg[i] = op(seg[i*2+1], seg[i*2+2]);
        }
    }

    void set(long long loc, S val){
        loc += N-1;
        seg[loc] = val;
        while (loc != 0){
            loc = (loc-1)/2;
            seg[loc] = op(seg[loc*2+1], seg[loc*2+2]);
        }
    }

    //op(a[l], ..., a[r])
    S prod (long long l, long long r) const{
        return _prod(l, r, 0, 0, N-1);
    }

    S all_prod() const{
        return seg[0];
    }

    S _prod (long long l, long long r, long long idx, long long bitl, long long bitr) const{
        if (r < bitl || l > bitr) return e();
        if (l <= bitl && bitr <= r) return seg[idx];

        long long bitm = (bitl+bitr)/2;
        return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr));
    }

    S get (long long i) const{
        return seg[i+N-1];
    }

    void show() const{
        for (int i=N-1; i<N*2-1; i++) cout << seg[i] << " ";
        cout << endl;
    }
};

long long op(long long a, long long b){
    return max(a, b);
}

const long long INF = (1LL<<62) - 1;

long long e(){
    return -INF;
}

using ll = long long;
 
int main(){

    ll N, l=0, ans=0;
    cin >> N;
    vector<ll> A(N), B(N), x(N), y(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) cin >> B[i];

    for (int i=0; i<N; i++){
        x[i] = A[i]+B[i];
        y[i] = A[i]-B[i];
    }

    SegTree<long long, op, e> mi(y), pl(x);

    auto judge = [&](auto i, auto j){
        return (pl.prod(i, j-1) < A[j]+B[j]) && (mi.prod(i, j-1) < A[j]-B[j]);
    };

    for (int r=0; r<N; r++){
        while(l<r && !judge(l, r)) l++;
        if (judge(l, r)) ans += r-l;
    }

    cout << ans << endl;
    return 0;
}
0