Submission #1040462

# Submission time Handle Problem Language Result Execution time Memory
1040462 2024-08-01T05:05:45 Z Requiem Sjeckanje (COCI21_sjeckanje) C++17
55 / 110
52 ms 564 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 "sjeckanje"
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;
int a[3003];

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

    /**
       Nhan xet cua ta la ta se dung cai difference array roi dp tren do
       Khi chuyen sang difference array thi ta co cac luu y:
       - Cac doan duoc chon phai co cung dau.
       - Cac doan duoc chon phai cach nhau 1 phan tu.
    **/

    int differenceArray[3003], dp[3030][2];

    //dp[i][j]: cho biet day con co tong lon nhat khi xet den vi tri i va j la dang duong hay am
    void update(int l, int r, int x){
         differenceArray[l] += x;
         differenceArray[r + 1] -= x;
    }

   int get(){
         int consNegative = 0, consPositive = 0;
         memset(dp, -0x3f, sizeof(dp));
         dp[1][0] = dp[1][1] = 0;

         for(int i = 1; i <= n; i++){
             for(int j = 0; j < 2; j++){
                 if (dp[i][j] > -inf){
//                     cout << i << ' ' << j <<' ' << dp[i][j] << endl;
                     if (j == 0) {
                         if (differenceArray[i + 1] > 0) maximize(dp[i + 1][0], dp[i][j] + differenceArray[i + 1]);
                     }
                     else {
                         if (differenceArray[i + 1] < 0) maximize(dp[i + 1][1], dp[i][j] - differenceArray[i + 1]);
                     }
                     maximize(dp[i + 1][0], dp[i][j]);
                     maximize(dp[i + 1][1], dp[i][j]);

                 }

             }
         }
         return max(dp[n][0], dp[n][1]);

    }
    void solve(){
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            differenceArray[i] = a[i] - a[i - 1];
        }
//        cout << get();

        for(int i = 1; i <= q; i++){
            int l, r, x;
            cin >> l >> r >> x;
            update(l, r, x);
            cout << get() << endl;
        }
    }
}

namespace subtask3{
    bool check(){
         return true;
    }

    void solve(){

    }
}
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: In function 'long long int subtask2::get()':
Main.cpp:46:14: warning: unused variable 'consNegative' [-Wunused-variable]
   46 |          int consNegative = 0, consPositive = 0;
      |              ^~~~~~~~~~~~
Main.cpp:46:32: warning: unused variable 'consPositive' [-Wunused-variable]
   46 |          int consNegative = 0, consPositive = 0;
      |                                ^~~~~~~~~~~~
Main.cpp: At global scope:
Main.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 49 ms 348 KB Output is correct
8 Correct 48 ms 564 KB Output is correct
9 Correct 52 ms 348 KB Output is correct
10 Correct 49 ms 348 KB Output is correct
11 Correct 46 ms 344 KB Output is correct
12 Correct 43 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 49 ms 348 KB Output is correct
8 Correct 48 ms 564 KB Output is correct
9 Correct 52 ms 348 KB Output is correct
10 Correct 49 ms 348 KB Output is correct
11 Correct 46 ms 344 KB Output is correct
12 Correct 43 ms 348 KB Output is correct
13 Incorrect 0 ms 356 KB Output isn't correct
14 Halted 0 ms 0 KB -