답안 #688023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
688023 2023-01-27T06:03:31 Z EthanKim8683 Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
using I=int;
using Lli=long long int;
const I N=200000;
const Lli MIN=-1e18;
I a_arr[N];
tuple<Lli,Lli,Lli,Lli,I,I>segs[2*N];
I n;
tuple<Lli,Lli,Lli,Lli,I,I>cmb(tuple<Lli,Lli,Lli,Lli,I,I>a,tuple<Lli,Lli,Lli,Lli,I,I>b){
  auto[nn1,ny1,yn1,yy1,l1,r1]=a;auto[nn2,ny2,yn2,yy2,l2,r2]=b;
  Lli nn3=max(nn1+nn2,max(ny1+nn2,max(nn1+yn2,ny1+yn2+abs(r1-l2))));
  Lli ny3=max(nn1+ny2,max(ny1+ny2,max(nn1+yy2,ny1+yy2+abs(r1-l2))));
  Lli yn3=max(yn1+nn2,max(yy1+nn2,max(yn1+yn2,yy1+yn2+abs(r1-l2))));
  Lli yy3=max(yn1+ny2,max(yy1+ny2,max(yn1+yy2,yy1+yy2+abs(r1-l2))));
  return{nn3,ny3,yn3,yy3,l1,r2};
}
void asn(I i,I x){
  segs[i+n]={0,0,0,MIN,x,x};
}
void bld(){
  for(I i=n-1;i>0;i--)segs[i]=cmb(segs[i<<1],segs[i<<1|1]);
}
void upd1(I i,I x){
  for(get<4>(segs[i+=n])+=x;i>1;i>>=1)segs[i>>1]=cmb(segs[i&~1],segs[i|1]);
}
void upd2(I i,I x){
  for(get<5>(segs[i+=n])+=x;i>1;i>>=1)segs[i>>1]=cmb(segs[i&~1],segs[i|1]);
}
Lli qry(I l,I r){
  tuple<Lli,Lli,Lli,Lli,I,I>lrs={0,MIN,MIN,MIN,0,0},rrs={0,MIN,MIN,MIN,0,0};
  for(l+=n,r+=n;l<r;l>>=1,r>>=1){
    if(l&1)lrs=cmb(lrs,segs[l++]);
    if(r&1)rrs=cmb(segs[--r],rrs);
  }
  auto[nn,ny,yn,yy,x,y]=cmb(lrs,rrs);
  return max(nn,max(ny,max(yn,yy)));
}
I main(){
  cin.tie(0)->sync_with_stdio(0);
  I q;cin>>n>>q;
  for(I i=0;i<n;i++)cin>>a_arr[i];
  for(I i=0;i<n;i++)asn(i,a_arr[i]);
  bld();
  while(q--){
    I l,r,x;cin>>l>>r>>x,l--,r--;
    upd1(l,x),upd2(r,x);
    printf("%lli\n",qry(0,n));
  }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -