Submission #725086

#TimeUsernameProblemLanguageResultExecution timeMemory
725086Bogdan1110Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
374 ms13096 KiB
#include <bits/stdc++.h> #define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} #define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);} #define ll long long #define ull unsigned long long #define pqueue priority_queue #define pb push_back #define fi first #define se second #define ld long double #define pii pair<int,int> #define pll pair<long long,long long> #define all(a) (a).begin(), (a).end() #define mp make_pair using namespace std; // order_of_key -> # less than k // find_by_order -> k-th element // pq max element const double eps = 0.00000001; const int NMAX = 200010; const ll inf = LLONG_MAX/3; const ll modi = 998244353; ll a[NMAX], d[NMAX]; ll n,q,s,t; ll diff(ll pret, ll x) { ll res = 0; if ( pret * x <= 0 ) { if ( abs(x) > abs(pret) ) { if ( pret < 0 ) { res -= t*abs(pret); } else { res += s*abs(pret); } x += pret; pret = 0; } } if (pret == 0) { if ( x >= 0 ) { res -= s*x; } else { res -= t*x; } return res; } if ( pret < 0 ) { res -= x*t; } else { res -= x*s; } return res; } void solve() { cin >> n >> q >> s >> t; for (int i = 0 ; i <= n ; i++ ) { cin >> a[i]; } ll res = 0; for (int i = 1; i <= n ; i++ ) { d[i] = a[i]-a[i-1]; if ( d[i] > 0 ) { res -= d[i]*s; } else { res -= d[i]*t; } } //cout << res << endl << endl; while(q--) { ll l,r,x; cin >> l >> r >> x; //cout << diff(d[l],x) << ' ' << diff(d[r+1],-x) << endl; res += diff(d[l],x); d[l] += x; if ( r < n ) { res += diff(d[r+1],-x); d[r+1] += -x; } cout << res << endl; } } int main () { FAST int t=1; /* cin >> t; //*/ int i = 1; while(t--) { //cout << "Case #" << i++ << ": " ; solve(); } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:102:9: warning: unused variable 'i' [-Wunused-variable]
  102 |     int i = 1;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...