結果
| 問題 |
No.1435 Mmm......
|
| コンテスト | |
| ユーザー |
yamake
|
| 提出日時 | 2021-03-19 22:40:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,993 bytes |
| コンパイル時間 | 2,431 ms |
| コンパイル使用メモリ | 194,788 KB |
| 実行使用メモリ | 10,260 KB |
| 最終ジャッジ日時 | 2024-11-18 23:44:26 |
| 合計ジャッジ時間 | 16,975 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 4 WA * 20 |
ソースコード
//#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){
a.first=min(a.first,b.first);
if(a.first<b.first)a.second=min(a.second,b.first);
else a.second=min(a.first,b.second);
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;
}
yamake