| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 794941 | Amylopectin | Sjeckanje (COCI21_sjeckanje) | C++14 | 305 ms | 29548 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
const long long mxn = 1e6 + 10;
long long hei[mxn] = {},dif[mxn] = {},sta[mxn][2] = {},se[mxn][2][2] = {};
long long ab(long long l)
{
    if(l < 0)
    {
        return -l;
    }
    return l;
}
long long bui(long long cl,long long cr,long long no)
{
    if(cl == cr)
    {
        se[no][0][0] = 0;
        se[no][0][1] = 0;
        se[no][1][0] = 0;
        se[no][1][1] = ab(dif[cl]);
        // sta[no][0] = 1;
        // sta[no][1] = 1;
        return 0;
    }
    long long i,j,mid = (cl+cr) / 2;
    bui(cl,mid,no*2);
    bui(mid+1,cr,no*2+1);
    if(dif[mid] * dif[mid+1] >= 0)
    {
        for(i=0; i<2; i++)
        {
            for(j=0; j<2; j++)
            {
                se[no][i][j] = se[no*2][i][1] + se[no*2+1][1][j];
                if(j > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][i][0]);
                }
                if(i > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][0][j]);
                }
            }
        }
    }
    else 
    {
        for(i=0; i<2; i++)
        {
            for(j=0; j<2; j++)
            {
                se[no][i][j] = max(se[no*2][i][0] + se[no*2+1][1][j]
                ,se[no*2][i][1] + se[no*2+1][0][j]);
                if(j > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][i][0]);
                }
                if(i > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][0][j]);
                }
            }
        }
    }
    return 0;
}
long long ad(long long cl,long long cr,long long no,long long tar)
{
    if(cl > tar || cr < tar)
    {
        return 0;
    }
    if(cl == cr)
    {
        se[no][0][0] = 0;
        se[no][0][1] = 0;
        se[no][1][0] = 0;
        se[no][1][1] = ab(dif[cl]);
        // sta[no][0] = 1;
        // sta[no][1] = 1;
        return 0;
    }
    long long i,j,mid = (cl+cr) / 2;
    ad(cl,mid,no*2,tar);
    ad(mid+1,cr,no*2+1,tar);
    if(dif[mid] * dif[mid+1] >= 0)
    {
        for(i=0; i<2; i++)
        {
            for(j=0; j<2; j++)
            {
                se[no][i][j] = se[no*2][i][1] + se[no*2+1][1][j];
                if(j > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][i][0]);
                }
                if(i > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][0][j]);
                }
            }  
        }
    }
    else 
    {
        for(i=0; i<2; i++)
        {
            for(j=0; j<2; j++)
            {
                se[no][i][j] = max(se[no*2][i][0] + se[no*2+1][1][j]
                ,se[no*2][i][1] + se[no*2+1][0][j]);
                if(j > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][i][0]);
                }
                if(i > 0)
                {
                    se[no][i][j] = max(se[no][i][j],se[no][0][j]);
                }
            }
        }
    }
    return 0;
}
int main()
{
    long long i,j,n,m,q,k,cn,cm,fn,fm,cl,cr,cva;
    scanf("%lld %lld",&n,&q);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&hei[i]);
        if(i > 0)
        {
            dif[i-1] = hei[i] - hei[i-1];
        }
    }
    bui(0,n-2,1);
    for(i=0; i<q; i++)
    {
        scanf("%lld %lld %lld",&cl,&cr,&cva);
        cl --;
        cr --;
        if(cl > 0)
        {
            dif[cl-1] += cva;
            ad(0,n-2,1,cl-1);
        }
        if(cr < n-1)
        {
            dif[cr] -= cva;
            ad(0,n-2,1,cr);
        }
        printf("%lld\n",se[1][1][1]);
    }
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
