結果

問題 No.1965 Heavier
ユーザー yamakeyamake
提出日時 2022-06-04 13:21:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,031 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 177,064 KB
実行使用メモリ 13,852 KB
最終ジャッジ日時 2023-10-21 02:38:40
合計ジャッジ時間 6,609 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 199 ms
13,852 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 202 ms
13,852 KB
testcase_26 AC 199 ms
13,852 KB
testcase_27 AC 183 ms
13,852 KB
testcase_28 AC 181 ms
13,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<"\n";
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const int inf=1.01e9;
constexpr int MOD=1000000007;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }

template<class T>
class SegTree{
    int n;
    vector<T> node;
    T e;
    function<T(T,T)> operation;
    function<T(T,T)> update;
    public:
    SegTree(int _n,T _e,function<T(T,T)> _operation,function<T(T,T)> _update):n(_n),e(_e),operation(_operation),update(_update){node.resize(n*2,e);}
    void change(int i,T x){
        i+=n;
        node[i]=update(node[i],x);
        while(i>1){
            i>>=1;
            node[i]=operation(node[i<<1|0],node[i<<1|1]);
        }
    }
    T get(int l,int r){
        T a=e;
        T b=e;
        l+=n;r+=n;
        while(l<r){
            if(l&1)a=operation(a,node[l++]);
            if(r&1)b=operation(node[--r],b);
            l>>=1;r>>=1;
        }
        return operation(a,b);
    }
    void input(vector<T>& _input){
        for(int i=0;i<n;++i){
            change(i,_input[i]);
        }
    }
};

signed main(){
    int n;cin>>n;
    vector<lint> a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    a.push_back(inf);b.push_back(linf);
    auto op=[](lint x,lint y){return max(x,y);};
    SegTree<lint> x(n+1,-linf,op,op);
    auto y=x;
    rep(i,n+1){
        x.change(i,a[i]-b[i]);
        y.change(i,a[i]+b[i]);
    }
    auto judge=[&](lint l,lint r)->bool{
        return x.get(l,r)<x.get(r,r+1)&&y.get(l,r)<y.get(r,r+1);
    };
    lint res=0;
    lint r=0;
    rep(i,n){
        while(judge(i,r))++r;
        res+=(r-i)*(r-i-1)/2;
        i=r;
    }
    cout<<res<<"\n";
    return 0;
}
0