Submission #519996

#TimeUsernameProblemLanguageResultExecution timeMemory
519996vinnipuh01Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
360 ms15608 KiB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long

using namespace std;

const long long oo = 1000000000000000000;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;


    freopen ( "sum.in", "r", stdin )
*/

int q, n, s, tt, a[ 200001 ], t[ 800001 ];

void upd( int v, int tl, int tr, int l, int r ) {
	if ( tl > r || tr < l )
		return;
	if ( tl >= l && tr <= r ) {
		t[ v ] += num;
		return;
	}
	int mid = ( tl + tr ) / 2;
	upd( v + v, tl, mid, l, r );
	upd( v + v + 1, mid + 1, tr, l, r );
}

void build( int v, int tl, int tr ) {
	if ( tl == tr ) {
		t[ v ] = a[ tl ];
		return;
	}
	int mid = ( tl + tr ) / 2;
	build( v + v, tl, mid );
	build( v + v + 1, mid + 1, tr );
}

void gett( int v, int tl, int tr, int pos ) {
	if ( tl > pos || tr < pos )
		return;
	if ( tl == tr ) {
		a[ tl ] = t[ v ];
		return;
	}
	if ( t[ v ] != 0 ) { 
		t[ v + v ] += t[ v ];
		t[ v + v + 1 ] += t[ v ];
		t[ v ] = 0;
	}
	int mid = ( tl + tr ) / 2;
	gett( v + v, tl, mid, pos );
	gett( v + v + 1, mid + 1, tr, pos );
}

main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	cin >> n;
	cin >> q;
	cin >> s >> tt;
	cin >> a[ 0 ];
	for ( int i = 1; i <= n; i ++ )
		cin >> a[ i ];
	for ( int i = 1; i <= n; i ++ ) {
		if ( a[ i ] > a[ i - 1 ] ) {
			sum -= s * ( a[ i ] - a[ i - 1 ] );
		}
		else
			sum += tt * ( a[ i - 1 ] - a[ i ] );
	}
	build( 1, 1, n );
	int l, r;
	while ( q -- ) {
		cin >> l >> r >> num;
		gett( 1, 1, n, l );
		gett( 1, 1, n, r );
		gett( 1, 1, n, l - 1 );
		if ( r < n )
			gett( 1, 1, n, r + 1 );
		upd( 1, 1, n, l, r );
		num = 0;
		if ( a[ l ] > a[ l - 1 ] )
			sum += s * ( a[ l ] - a[ l - 1 ] );
		else
			sum -= tt * ( a[ l - 1 ] - a[  l] );
		if ( r < n ) {
			if ( a[ r + 1 ] > a[ r ] )
				sum += s * ( a[ r + 1 ] - a[ r ] );
			else
				sum -= tt * ( a[ r ] - a[ r + 1 ] );
		}
		gett( 1, 1, n, l );
		gett( 1, 1, n, r );
		if ( a[ l ] > a[ l - 1 ] )
			sum -= s * ( a[ l ] - a[ l - 1 ] );
		else
			sum += tt * ( a[ l - 1 ] - a[ l ] );
		if ( r < n ) {
			if ( a[ r + 1 ] > a[ r ] )
				sum -= s * ( a[ r + 1 ] - a[ r ] );
			else
				sum += tt * ( a[ r ] - a[ r + 1 ] );
		}
		cout << sum << "\n";
	}
}

/*



*/

Compilation message (stderr)

foehn_phenomena.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   85 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...