답안 #977808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977808 2024-05-08T11:18:27 Z Requiem Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
418 ms 524288 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "recipe"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 2e5 + 9;
int a[MAXN];

int n,q;
int l,r,x,d[MAXN];
struct Node{
    int dp[2][2];
    Node(){
       memset(dp,-0x3f,sizeof(dp));
    }
};
Node st[MAXN<<2];
void merging(int node,int l,int r){
    int mid = (l+r)>>1;
    memset(st[node].dp,-0x3f,sizeof(st[node].dp));
    for(int i=0;i<=1;i++){
        for(int j=0;j<=1;j++){
            int l = i;
            int r = j;
            for(int t=0;t<=1;t++){
                for(int z=0;z<=1;z++){

                    if (t!=1 or z!=1){
//                        cout<<i<<' '<<j<<' '<<l<<' '<<t<<' '<<z<<' '<<r<<endl;
                        maximize(st[node].dp[i][j], st[node<<1].dp[l][t] + st[node<<1|1].dp[z][r]);
                    }
                    else if (d[mid] * d[mid+1] >= 0){
                        maximize(st[node].dp[i][j], st[node<<1].dp[l][t] + st[node<<1|1].dp[z][r]);
                    }

                }
            }
        }
    }
}
void build(int node,int l,int r){
    if (l==r){
        st[node].dp[0][0] = 0;
        st[node].dp[1][1] = abs(d[l]);
        return;
    }
    int mid = (l+r)>>1;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
    merging(node,l,r);
}

void upd(int node,int l,int r,int pos){
    if (l==r){
        st[node].dp[0][0] = 0;
        st[node].dp[1][1] = d[l];

        return;
    }
    int mid = (l+r)>>1;
    if (pos <= mid) upd(node<<1,l,mid,pos);
    else upd(node<<1|1,mid+1,r,pos);
    merging(node,l,r);


}
main()
{
    fast;
    freopen(TASKNAME".inp","r",stdin);
    freopen(TASKNAME".out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        d[i] = a[i] - a[i+1];
    }
    build(1,1,n-1);
    for(int i=1;i<=q;i++){

        cin>>l>>r>>x;
        d[l-1] -= x;
        d[r] += x;
        if (l-1 >= 1 and l-1 <= n-1) upd(1,1,n-1,l-1);
        if (r >= 1 and r <= n-1) upd(1,1,n-1,r);
        int ans = 0;
        for(int t=0;t<=1;t++){
            for(int z=0;z<=1;z++){
                ans = max(ans, st[1].dp[t][z]);
            }
        }
        cout<<ans<<endl;
    }
}

Compilation message

Main.cpp:82:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   82 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:85:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |     freopen(TASKNAME".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:86:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |     freopen(TASKNAME".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 418 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 418 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 418 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -