結果

問題 No.1435 Mmm......
ユーザー yamakeyamake
提出日時 2021-03-19 22:44:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 966 ms / 2,000 ms
コード長 1,993 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 191,452 KB
実行使用メモリ 10,320 KB
最終ジャッジ日時 2023-08-12 03:31:50
合計ジャッジ時間 16,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,504 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 409 ms
7,856 KB
testcase_07 AC 512 ms
8,792 KB
testcase_08 AC 609 ms
9,680 KB
testcase_09 AC 554 ms
9,112 KB
testcase_10 AC 471 ms
8,256 KB
testcase_11 AC 461 ms
8,356 KB
testcase_12 AC 424 ms
7,728 KB
testcase_13 AC 412 ms
7,792 KB
testcase_14 AC 299 ms
6,752 KB
testcase_15 AC 637 ms
9,844 KB
testcase_16 AC 510 ms
9,004 KB
testcase_17 AC 344 ms
7,004 KB
testcase_18 AC 643 ms
10,128 KB
testcase_19 AC 451 ms
8,344 KB
testcase_20 AC 579 ms
9,324 KB
testcase_21 AC 966 ms
10,320 KB
testcase_22 AC 936 ms
10,232 KB
testcase_23 AC 651 ms
10,076 KB
testcase_24 AC 654 ms
10,116 KB
testcase_25 AC 654 ms
10,240 KB
testcase_26 AC 650 ms
10,032 KB
testcase_27 AC 651 ms
10,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#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 debug(output) cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
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(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  auto op=[](int a,int b){return max(a,b);};
  auto op2=[](P a,P b){
    if(a.first<b.first)a.second=min(a.second,b.first);
    else a.second=min(a.first,b.second);
    a.first=min(a.first,b.first);
    return a;
  };
  SegTree<int> M(n,0,op,op);
  M.input(a);
  SegTree<P> m(n,{inf,inf},op2,op2);
  vector<P> b(n);
  rep(i,n){
    b[i]={a[i],inf};
  }
  m.input(b);
  lint res=0;
  rep(i,n-1){
    int l=i+1;int r=n;
    while(r-l>1){
      int mid=(r+l)/2;
      auto hoge=m.get(i,mid+1);
      if(M.get(i,mid+1)<=hoge.first+hoge.second)l=mid;
      else r=mid;
    }
    res+=l-i;
  }
  cout<<res<<"\n";
  return 0;
}
0