Submission #68208

#TimeUsernameProblemLanguageResultExecution timeMemory
68208BTheroFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
573 ms165724 KiB
// Why I am so dumb? :c #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second using namespace std; typedef long long ll; const int MAXN = (int)2e5 + 5; ll t[MAXN << 2]; int n, q, a, b; int arr[MAXN]; ll ans; void segUpd(int v, int tl, int tr, int l, int r, int x) { if (l > r || tl > r || tr < l) { return; } if (l <= tl && tr <= r) { t[v] += x; return; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); segUpd(c1, tl, mid, l, r, x); segUpd(c2, mid + 1, tr, l, r, x); } ll getVal(int v, int tl, int tr, int ps) { if (tl == tr) { return t[v] + arr[tl]; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); if (ps <= mid) { return t[v] + getVal(c1, tl, mid, ps); } else { return t[v] + getVal(c2, mid + 1, tr, ps); } } ll calc(int ps) { if (ps < 0 || ps == n) { return 0ll; } ll v1 = getVal(1, 0, n, ps); ll v2 = getVal(1, 0, n, ps + 1); if (v1 < v2) { return a * (v1 - v2); } else { return b * (v1 - v2); } } void solve() { scanf("%d %d %d %d", &n, &q, &a, &b); for (int i = 0; i <= n; ++i) { scanf("%d", &arr[i]); } for (int i = 0; i < n; ++i) { ans += calc(i); } for (int i = 1; i <= q; ++i) { int l, r, x; scanf("%d %d %d", &l, &r, &x); ans -= calc(l - 1); ans -= calc(r); segUpd(1, 0, n, l, r, x); ans += calc(l - 1); ans += calc(r); printf("%lld\n", ans); } } int main() { int tt = 1; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'void solve()':
foehn_phenomena.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d", &n, &q, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);  
   ~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:88:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d %d", &l, &r, &x);  
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...