結果

問題 No.1435 Mmm......
ユーザー chocoruskchocorusk
提出日時 2021-03-19 22:05:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 2,422 bytes
コンパイル時間 3,542 ms
コンパイル使用メモリ 195,776 KB
実行使用メモリ 13,296 KB
最終ジャッジ日時 2023-08-12 02:18:48
合計ジャッジ時間 6,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 41 ms
11,696 KB
testcase_07 AC 48 ms
12,488 KB
testcase_08 AC 56 ms
12,908 KB
testcase_09 AC 51 ms
12,548 KB
testcase_10 AC 45 ms
12,344 KB
testcase_11 AC 46 ms
12,088 KB
testcase_12 AC 42 ms
11,744 KB
testcase_13 AC 41 ms
11,748 KB
testcase_14 AC 31 ms
7,928 KB
testcase_15 AC 56 ms
13,028 KB
testcase_16 AC 49 ms
12,476 KB
testcase_17 AC 34 ms
8,348 KB
testcase_18 AC 58 ms
13,080 KB
testcase_19 AC 44 ms
12,188 KB
testcase_20 AC 52 ms
12,952 KB
testcase_21 AC 111 ms
13,016 KB
testcase_22 AC 101 ms
13,296 KB
testcase_23 AC 93 ms
13,020 KB
testcase_24 AC 92 ms
13,008 KB
testcase_25 AC 92 ms
12,944 KB
testcase_26 AC 89 ms
12,988 KB
testcase_27 AC 92 ms
12,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	/*Monoid query(int a, int b){ //演算が非可換のとき
		a+=sz, b+=sz;
		Monoid retl=e, retr=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) retr=f(seg[--b], retr);
			if(a&1) retl=f(retl, seg[a++]);
		}
		return f(retl, retr);
	}*/

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int main()
{
    int n; cin>>n;
    vector<int> a(n);
    vector<P> b(n);
    const ll INF=1e9+7;
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i]=P(a[i], INF);
    }
    SegmentTree<int> seg(n, [](int x, int y){ return max(x, y);}, 0, a);
    auto f=[](P p, P q){
        if(p.first>q.first) swap(p, q);
        return P(p.first, min(p.second, q.first));
    };
    SegmentTree<P> seg2(n, f, P(INF, INF), b);
    ll ans=0;
    int r=0;
    for(int i=0; i<n; i++){
        r=max(r, i+2);
        for(; r<=n; r++){
            int M=seg.query(i, r);
            P p=seg2.query(i, r);
            if(M>p.first+p.second) break;
        }
        ans+=r-i-2;
    }
    cout<<ans<<endl;
    return 0;
}
0