답안 #439886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439886 2021-07-01T05:44:41 Z XBoRickie Sjeckanje (COCI21_sjeckanje) C++11
110 / 110
826 ms 49240 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> cp;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<cp> vcp;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
 
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for( int i = (l) ; i < (r) ; i++ )
#define forb(i,r,l) for( int i = (r) ; i >= (l) ; i-- )
#define log2i(x) (64 - __builtin_clzll(1ll*(x)) - 1)
#define numBit(x) (__builtin_popcountll(1ll*(x)))
#define getBit(x,i) ((x)>>(i)&1)
#define Pi acos(-1.0l)
#define sz(x) int(x.size())
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';
 
const int N = 2e5+7;
const ll inf = 3e18l+7;
int n,q;
ll a[N];
 
struct Node {
    ll val[4],lhs,rhs;
    Node():lhs(0),rhs(0) {
        forw(i,0,4) val[i]=0;
    }
    Node(ll x):lhs(x),rhs(x) {
        forw(i,0,4) val[i]=0;
        val[3]=abs(x);
    }
    ll operator [](int x) const {return val[x];}
    ll& operator [](int x) {return val[x];}
};
 
Node merge(const Node &x, const Node &y) {
    Node res;
    res.lhs=x.lhs;
    res.rhs=y.rhs;
    forw(i,0,4) forw(j,0,3+(x.rhs*y.lhs>=0)) {
        res[i]=max(res[i],x[i/2*2+j/2]+y[j%2*2+i%2]);
    }
    return res;
}
 
struct SegTree {
    vector<Node> _a;
    int _n;
    SegTree():_a(0),_n(0) {}
    ll operator [](int x) const {return _a[1].val[x];}
    ll& operator [](int x) {return _a[1].val[x];}
    void init(int len) {
        _a.assign(4*(_n=len)+4,Node());
        build(1,0,_n-1);
    }
    void build(int idx, int l, int r) {
        if(l==r) _a[idx]=Node(a[l]);
        else {
            int mid=(l+r)>>1, k=idx<<1;
            build(k,l,mid);
            build(k+1,mid+1,r);
            _a[idx]=merge(_a[k],_a[k+1]);
        }
    }
    void upd(int x, ll v, int idx, int l, int r) {
        if(x<l||r<x||l>r) return;
        if(l==r) _a[idx]=Node(_a[idx].rhs+v);
        else {
            int mid=(l+r)>>1, k=idx<<1;
            upd(x,v,k,l,mid);
            upd(x,v,k+1,mid+1,r);
            _a[idx]=merge(_a[k],_a[k+1]);
        }
    }
    void upd(int x, ll v) {upd(x,v,1,0,_n-1);}
}T;
 
int main() {
    fastIO;
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif // ONLINE_JUDGE
 
    cin >> n >> q;
    forw(i,0,n) cin >> a[i];
    forw(i,0,n-1) a[i]=a[i+1]-a[i];
    T.init(n-1);
    while(q--) {
        int l,r,x; cin >> l >> r >> x;
        l--, r--;
        T.upd(l-1,x); T.upd(r,-x);
        ll ans=-inf;
        forw(i,0,4) ans=max(ans,T[i]);
        cout << ans << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 7 ms 1032 KB Output is correct
8 Correct 6 ms 972 KB Output is correct
9 Correct 7 ms 972 KB Output is correct
10 Correct 7 ms 972 KB Output is correct
11 Correct 7 ms 972 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 7 ms 1032 KB Output is correct
8 Correct 6 ms 972 KB Output is correct
9 Correct 7 ms 972 KB Output is correct
10 Correct 7 ms 972 KB Output is correct
11 Correct 7 ms 972 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
13 Correct 826 ms 48628 KB Output is correct
14 Correct 779 ms 48536 KB Output is correct
15 Correct 797 ms 48536 KB Output is correct
16 Correct 791 ms 48608 KB Output is correct
17 Correct 794 ms 48336 KB Output is correct
18 Correct 728 ms 49240 KB Output is correct