답안 #579035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579035 2022-06-18T10:22:29 Z nohaxjustsoflo Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 340 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
//mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN = 5e5+25000;
const int mod = 1e9+9;
const int mxlogN = 20;
const int mxK = 26;
const ll inf = 1e18;
const int K=600;
///left, right 00, 1+, 2-
ll v[mxN][3][3], a[mxN], lz[mxN];
int sz;
void recalc(int i)
{
    for(int j=0; j<3; j++) for(int k=0; k<3; k++) v[i][j][k]=max(v[i*2+1][j][k], v[i*2+2][j][k]);
    for(int j=0; j<3; j++) for(int k=0; k<3; k++) for(int l=0; l<3; l++) for(int m=0; m<3; m++)
    {
        if(k&&l)
        {
            if(k==l) continue;
        }
        else if(k||l) continue;
        v[i][j][m]=max(v[i][j][m],v[i*2+1][j][k]+v[i*2+2][l][m]);
    }
}
void build2(int n, int i=0, int Lx=0, int Rx=sz)
{
    if(Rx-Lx==1)
    {
        for(int j=0; j<3; j++) for(int k=0; k<3; k++) v[i][j][k]=-inf;
        v[i][0][1]=a[Lx];
        v[i][1][0]=a[Lx];
        v[i][0][2]=-a[Lx];
        v[i][2][0]=-a[Lx];
        v[i][0][0]=0;
        return;
    }
    int m = (Lx+Rx)/2;
    build2(n, i*2+1, Lx, m);
    build2(n, i*2+2, m, Rx);
    recalc(i);
}
void build(int n)
{
    sz=1;
    while(sz < n) sz <<= 1;
    build2(n);
}
void lazy(int i)
{
    if(lz[i])
    {
        lz[i*2+1]+=lz[i];
        for(int j=0; j<3; j++) for(int k=0; k<3; k++)
        {
            ll add=0;
            if(j==1) add++;
            if(k==1) add++;
            if(j==2) add--;
            if(k==2) add--;
            v[i*2+1][j][k]+=lz[i]*add;
        }
        for(int j=0; j<3; j++) for(int k=0; k<3; k++)
        {
            ll add=0;
            if(j==1) add++;
            if(k==1) add++;
            if(j==2) add--;
            if(k==2) add--;
            v[i*2+2][j][k]+=lz[i]*add;
        }
        lz[i*2+2]+=lz[i];
        lz[i]=0;
    }
}
void add(int l, int r, ll V, int i=0, int Lx=0, int Rx=sz)
{
    if(Rx <= l || Lx >= r) return;
    if(Lx >= l && Rx <= r)
    {
        for(int j=0; j<3; j++) for(int k=0; k<3; k++)
        {
            ll a=0;
            if(j==1) a++;
            if(k==1) a++;
            if(j==2) a--;
            if(k==2) a--;
            v[i][j][k]+=V*a;
        }
        lz[i]+=V;
        return;
    }
    int m = (Rx+Lx)/2;
    lazy(i);
    add(l, r, V, i*2+1, Lx, m);
    add(l, r, V, i*2+2, m, Rx);
    recalc(i);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, q; cin >> n >> q;
    for(int i=0; i<n; i++) cin >> a[i];
    build(n);
    //cout << v[0][0][0] << "\n";
    while(q--)
    {
        int l, r, x; cin >> l >> r >> x;
        add(l-1,r,x);
        cout << v[0][0][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 -