Submission #680856

# Submission time Handle Problem Language Result Execution time Memory
680856 2023-01-11T23:07:10 Z AranMaster Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 340 KB
#include <bits/stdc++.h>
#define B17 ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define ll long long 
using namespace std;
const int maxn = 2e6 + 10;
int a[maxn] ,n , q;
ll ans;
int l , r, x;
bool cut[maxn];

void solve(){
    cin >> l >> r >> x;
    for(int i = l; i <= r; i++)
        a[i] += x;
    ans = 0;
    bool b_29 = false;
    int b1 = 0;
    for(int i = 1; i < n; i++){//***
        ll jo1 = abs(a[i] - a[i - 1]) , jo2 = abs(a[i] - a[i + 1]);
        if((i > 1) && ((a[i] < a[i + 1] && a[i] < a[i - 1] )|| (a[i] > a[i + 1] && a[i] > a[i - 1]))){ // dare ya tape
//            cout << "slam mola" << i << endl;;
            if(!b_29){
                ans -= jo1;
                ans += jo2;
                b_29 = 1;
                b1 = jo1;
            }
            else{
                if(jo2 > jo1){
                    ans -= jo1;
                    ans += b1;
                    ans += jo2;
                    b_29 = 0;
                }
            }
        }
        else {
            b_29 = 0;
            ans += jo2;
        }
    }

    cout << ans << endl;
}

int main(){
    B17;
    cin >> n >> q;

    for(int i = 1; i <= n; i++)cin >> a[i];

    while(q--) solve();
}

/* temp
4 3
2 0 2 1
4 4 1
2 2 3
1 3 2


4 3
1 2 3 4
1 2 1
1 1 2
2 3 1



    */
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -