結果

問題 No.3185 Three Abs
ユーザー alcea
提出日時 2025-06-20 21:55:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 811 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 4,107 ms
コンパイル使用メモリ 255,608 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2025-06-20 21:55:55
合計ジャッジ時間 24,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
ll op(ll x,ll y){return max(x,y);}
ll e(){return ll(-2e18);}
ll comp(ll x,ll y){return x+y;}
ll mapi(ll x,ll y){return x+y;}
ll id(){return 0;}
void solve(){
  int n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  lazy_segtree<ll,op,e,ll,mapi,comp,id> lseg0(n),lseg1(n);
  ll rsum=0,sum=accumulate(a,a+n,0LL);
  for(int i=n-1;i>=0;i--){
    rsum+=a[i];
    sum-=a[i];
    lseg0.set(i,abs(rsum)+sum);
    lseg1.set(i,abs(rsum)-sum);
  }
  ll lsum=0,ans=0;
  for(int i=0;i<n-2;i++){
    lsum+=a[i];
    lseg0.apply(i+1,n,-a[i]);
    lseg1.apply(i+1,n,a[i]);
    ans=max(ans,abs(lsum)+max(lseg0.prod(i+1,n),lseg1.prod(i+1,n)));
  }
  cout<<ans<<endl;
}
int main(){
  int t;
  cin>>t;
  while(t--) solve();
}
0