Submission #1291971

#TimeUsernameProblemLanguageResultExecution timeMemory
1291971thaibeo123Foehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
96 ms6480 KiB
#include <bits/stdc++.h> using namespace std; #define NAME "A" #define ll long long #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define MASK(x) (1ll << (x)) #define BIT(x, i) (((x) >> (i)) & 1) const int N = 2e5 + 5; struct FenwickTree { int n; vector<ll> fen; FenwickTree() {} FenwickTree(int n): n(n), fen(n + 5) {} void update(int x, int v) { for (int i = x; i <= n; i += i & -i) { fen[i] += v; } } ll get(int x) { ll res = 0; for (int i = x; i > 0; i -= i & -i) { res += fen[i]; } return res; } }; FenwickTree fen; int n, q; ll s, t; int a[N]; ll compute(int x, int y) { if (y > n) return 0; ll ans = 0; ll one = a[x] + fen.get(x), two = a[y] + fen.get(y); if (one < two) { ans += s * (two - one); } else { ans += t * (one - two); } return ans; } void input() { cin >> n >> q >> s >> t; s = -s; for (int i = 0; i <= n; i++) { cin >> a[i]; } } void solve() { fen = FenwickTree(n); ll ans = 0; for (int i = 1; i <= n; i++) { if (a[i - 1] < a[i]) { ans += s * (a[i] - a[i - 1]); } else { ans += t * (a[i - 1] - a[i]); } } while (q--) { int l, r, x; cin >> l >> r >> x; ans -= compute(l - 1, l); ans -= compute(r, r + 1); fen.update(l, x); fen.update(r + 1, -x); ans += compute(l - 1, l); ans += compute(r, r + 1); cout << ans << "\n"; } } signed main() { if (fopen(NAME".INP", "r")) { freopen(NAME".INP", "r", stdin); freopen(NAME".OUT", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int t = 1; //cin >> t; while (t--) { input(); solve(); } return 0; }

Compilation message (stderr)

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