Submission #1032090

#TimeUsernameProblemLanguageResultExecution timeMemory
1032090LTTrungCHLSjeckanje (COCI21_sjeckanje)C++17
55 / 110
2009 ms6492 KiB
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n, q;
int a[N];
long long d[N], dp[N];;
void solve(){
    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];
    }
    for (int i = 1;i <= q;++i){
        int l, r, x;
        cin >> l >> r >> x;
        for (int i = l;i <= r;++i){
            a[i] += x;
        }
        d[l - 1] -= x;
        d[r] += x;
        for (int i = 1;i < n;++i){
            if (d[i] * d[i - 1] < 0){
                dp[i] = max(dp[i - 1], dp[i - 2] + abs(d[i]));
            } else dp[i] = dp[i - 1] + abs(d[i]);
        }
        cout << dp[n - 1] <<"\n";
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    if (fopen("ltt.inp", "r")){
        freopen("ltt.inp", "r", stdin);
        freopen("ltt.out", "w", stdout);
    }
//    int t;
//    cin >> t;
//    while(t--){
    solve();
//    }
    return 0;
}






Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen("ltt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("ltt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...