답안 #1032090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032090 2024-07-23T11:06:19 Z LTTrungCHL Sjeckanje (COCI21_sjeckanje) C++17
55 / 110
2000 ms 6492 KB
///***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

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 15 ms 2648 KB Output is correct
8 Correct 16 ms 2648 KB Output is correct
9 Correct 17 ms 2668 KB Output is correct
10 Correct 15 ms 2652 KB Output is correct
11 Correct 15 ms 2668 KB Output is correct
12 Correct 20 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 15 ms 2648 KB Output is correct
8 Correct 16 ms 2648 KB Output is correct
9 Correct 17 ms 2668 KB Output is correct
10 Correct 15 ms 2652 KB Output is correct
11 Correct 15 ms 2668 KB Output is correct
12 Correct 20 ms 2652 KB Output is correct
13 Execution timed out 2009 ms 6492 KB Time limit exceeded
14 Halted 0 ms 0 KB -