Submission #1040457

# Submission time Handle Problem Language Result Execution time Memory
1040457 2024-08-01T04:36:36 Z Requiem Sjeckanje (COCI21_sjeckanje) C++17
55 / 110
21 ms 656 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 ""
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;

int n, q;

namespace subtask2{
    bool check(){
        return n <= 3000 and q <= 3000;
    }

    int preMax[3003], preMin[3030], a[3030], dp[3030];

    void update(int l, int r, int x){
         for(int i = l; i <= r; i++){
             a[i] += x;
         }
    }

    int get(){

        memset(dp, 0, sizeof(dp));
        memset(preMax, -0x3f, sizeof(preMax));
        memset(preMin, -0x3f, sizeof(preMin));
        dp[0] = 0;
        preMax[0] = dp[0] + a[1];
        preMin[0] = dp[0] - a[1];
        for(int i = 1; i <= n; i++){
            maximize(dp[i], preMax[i - 1] - a[i]);
            maximize(dp[i], preMin[i - 1] + a[i]);

            preMax[i] = max(preMax[i - 1], dp[i] + a[i + 1]);
            preMin[i] = max(preMin[i - 1], dp[i] - a[i + 1]);
        }
        return dp[n];
    }
    void solve(){
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }

        for(int i = 1; i <= q; i++){
            int l, r, x;
            cin >> l >> r >> x;
            update(l, r, x);
            cout << get() << endl;
        }
    }
}
main()
{
    fast;
    if (fopen(TASKNAME".inp","r")){
        freopen(TASKNAME".inp","r",stdin);
        freopen(TASKNAME".out","w",stdout);
    }
    cin >> n >> q;
    if (subtask2::check()) return subtask2::solve(), 0;
}
/**
Warning:
- MLE / TLE?
- Gioi han mang?
- Gia tri max phai luon gan cho -INF
- long long co can thiet khong?
- tran mang.
- code can than hon
- Nho sinh test de tranh RTE / TLE

--> Coi lai truoc khi nop
**/

Compilation message

Main.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 19 ms 604 KB Output is correct
8 Correct 20 ms 656 KB Output is correct
9 Correct 19 ms 604 KB Output is correct
10 Correct 19 ms 604 KB Output is correct
11 Correct 19 ms 640 KB Output is correct
12 Correct 21 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 19 ms 604 KB Output is correct
8 Correct 20 ms 656 KB Output is correct
9 Correct 19 ms 604 KB Output is correct
10 Correct 19 ms 604 KB Output is correct
11 Correct 19 ms 640 KB Output is correct
12 Correct 21 ms 600 KB Output is correct
13 Incorrect 0 ms 344 KB Output isn't correct
14 Halted 0 ms 0 KB -