結果

問題 No.1965 Heavier
ユーザー yamake
提出日時 2022-06-04 13:21:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 2,033 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 176,144 KB
実行使用メモリ 13,960 KB
最終ジャッジ日時 2024-09-21 03:39:45
合計ジャッジ時間 7,081 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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-1;
}
cout<<res<<"\n";
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0