Submission #46641

#TimeUsernameProblemLanguageResultExecution timeMemory
46641golubFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
163 ms7592 KiB
//#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,sse4") //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("unroll-all-loops") #include <bits/stdc++.h> //#define TASK "lca" #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define F first #define S second #define pb push_back #define int long long #define pii pair<int, int> typedef long long ll; //typedef long double ld; using namespace std; const int INF = 1e18; const int MAXN = 1e8; const int MOD = 1e9 + 7; const double EPS = 1e-12; //char buf[(int)1e9]; //size_t p_ = 0; // //inline void *operator new(size_t n_) { // p_ += n_; // return buf + p_ - n_; //} //inline void operator delete(void*) {}; ll power(ll x, ll n, ll mod = 1e9 + 7) { if (n == 0) return 1ll; if (n & 1ll) return power(x, n - 1ll, mod) * x % mod; ll tmp = power(x, n >> 1ll, mod); return (tmp * tmp) % mod; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd (b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } signed main() { #ifndef LOCAL #ifdef TASK freopen(TASK".in", "r", stdin); freopen(TASK".out", "w", stdout); #endif #endif #ifdef LOCAL //freopen("/Users/alekseygolub/Desktop/с++/ABS/ABS/input.txt", "r", stdin); #endif iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(924653523); // == SOLUTION == // int n, q, s, t; cin >> n >> q >> s >> t; vector<int> a(n + 1); for (int i = 0; i < n + 1; i++) { cin >> a[i]; } vector<int> d(n); int ans = 0; for (int i = 0; i < n; i++) { d[i] = a[i + 1] - a[i]; if (d[i] > 0) ans -= s * d[i]; if (d[i] <= 0) ans += abs(t * d[i]); } //cout << ans << '\n'; for (int i = 0; i < q; i++) { int l, r, x; cin >> l >> r >> x; l--; r; if (l >= 0) { if (d[l] > 0) { ans += s * d[l]; } else { ans -= abs(t * d[l]); } d[l] += x; if (d[l] > 0) ans -= s * d[l]; if (d[l] <= 0) ans += abs(t * d[l]); } if (r < n) { if (d[r] > 0) { ans += s * d[r]; } else { ans -= abs(t * d[r]); } d[r] -= x; if (d[r] > 0) ans -= s * d[r]; if (d[r] <= 0) ans += abs(t * d[r]); } // for (auto aa: d) cout << aa << " "; // cout << "\n"; cout << ans << "\n"; } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:85:15: warning: statement has no effect [-Wunused-value]
         l--; r;
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...