結果

問題 No.1435 Mmm......
ユーザー yamakeyamake
提出日時 2021-03-19 22:37:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,972 bytes
コンパイル時間 2,433 ms
コンパイル使用メモリ 196,228 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-04-29 17:50:27
合計ジャッジ時間 26,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 971 ms
7,808 KB
testcase_07 AC 1,209 ms
8,960 KB
testcase_08 AC 1,449 ms
9,856 KB
testcase_09 AC 1,329 ms
9,344 KB
testcase_10 AC 1,183 ms
8,576 KB
testcase_11 AC 1,097 ms
8,448 KB
testcase_12 AC 1,024 ms
8,192 KB
testcase_13 AC 996 ms
8,064 KB
testcase_14 AC 722 ms
6,656 KB
testcase_15 AC 1,577 ms
9,984 KB
testcase_16 AC 1,227 ms
8,832 KB
testcase_17 AC 832 ms
7,296 KB
testcase_18 AC 1,553 ms
10,220 KB
testcase_19 AC 1,064 ms
8,320 KB
testcase_20 AC 1,363 ms
9,600 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,554 ms
10,224 KB
testcase_24 AC 1,564 ms
10,240 KB
testcase_25 AC 1,557 ms
10,240 KB
testcase_26 AC 1,557 ms
10,436 KB
testcase_27 AC 1,550 ms
10,240 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){
    vector<int> v={a.first,a.second,b.first,b.second};
    sort(v.begin(),v.end());
    P res={v[0],v[1]};
    return res;
  };
  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