Submission #891264

#TimeUsernameProblemLanguageResultExecution timeMemory
891264Tien_NoobFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
137 ms12416 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" using namespace std; const int N = 2e5; int a[N + 1], n, q; long long res, s, t; struct FenwickTree { long long tree[N + 1]; void add(int pos, int val) { for (; pos <= n; pos |= pos + 1) { tree[pos] += val; } } void add(int l, int r, int val) { add(l, val); add(r + 1, - val); } long long get(int pos) { long long ret = a[pos]; for (; pos >= 0; pos = (pos & (pos + 1)) - 1) { ret += tree[pos]; } return ret; } } tree; void read() { cin >> n >> q >> s >> t; for (int i = 0; i <= n; ++ i) { cin >> a[i]; if (i == 0) { continue; } if (a[i - 1] < a[i]) { res += (a[i] - a[i - 1]) * s; } else { res -= (a[i - 1] - a[i]) * t; } } } long long val(int i) { long long x = tree.get(i), y = tree.get(i + 1); if (x < y) { return (y - x) * s; } else { return (y - x) * t; } } void solve() { while(q--) { int l, r, x; cin >> l >> r >> x; if (r < n) { res -= val(r); } res -= val(l - 1); tree.add(l, r, x); if (r < n) { res += val(r); } res += val(l - 1); cout << -res << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...