답안 #987419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987419 2024-05-22T18:02:54 Z cpdreamer Sjeckanje (COCI21_sjeckanje) C++14
55 / 110
2000 ms 6240 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
const int max_n=INT_MAX;
typedef long long  ll;
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define  P pair
#define V vector
const long long MOD = 1000000007; // 1e9 + 7


void file(){
    freopen("input.txt.txt","r",stdin);
    freopen("output.txt.txt","w",stdout);
}
void setio(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
struct station{
    int p;
    int c;
    int l;
    int r;
};
bool custom(station a,station b) {
    return a.p < b.p;
}

void solve(){
    ll n;
    cin>>n;
    ll q;
    cin>>q;
    ll A[n+1];
    for(int i=1;i<=n;i++){
        cin>>A[i];
    }
    ll dp[n+1];
    dp[0]=0;
    dp[1]=0;
    while(q--){
        int l,r;
        ll v;
        cin>>l>>r;
        cin>>v;
        for(int i=l;i<=r;i++){
            A[i]+=v;
        }
        ll maxer1=LONG_LONG_MIN;
        ll maxer2=LONG_LONG_MIN;
        for(int i=1;i<=n;i++){
            maxer1=max(maxer1,dp[i-1]-A[i]);
            maxer2=max(maxer2,dp[i-1]+A[i]);
            dp[i]=max(A[i]+maxer1,-A[i]+maxer2);
        }
        cout<<dp[n]<<endl;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //file();
    solve();

    return 0;
}

Compilation message

Main.cpp: In function 'void file()':
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen("input.txt.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("output.txt.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void setio(std::string)':
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 604 KB Output is correct
8 Correct 31 ms 604 KB Output is correct
9 Correct 32 ms 604 KB Output is correct
10 Correct 31 ms 600 KB Output is correct
11 Correct 32 ms 592 KB Output is correct
12 Correct 32 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 604 KB Output is correct
8 Correct 31 ms 604 KB Output is correct
9 Correct 32 ms 604 KB Output is correct
10 Correct 31 ms 600 KB Output is correct
11 Correct 32 ms 592 KB Output is correct
12 Correct 32 ms 604 KB Output is correct
13 Execution timed out 2032 ms 6240 KB Time limit exceeded
14 Halted 0 ms 0 KB -