제출 #1088723

#제출 시각아이디문제언어결과실행 시간메모리
1088723SunbaeFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
107 ms14736 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 2e5 + 5; int n, q; ll t[2], L[2], R[2], a[N], d[N], bit[N], sum = 0; void upd(int i, ll val){ for(; i<N; i+=i&-i) bit[i] += val;} ll qry(int i){ ll res = 0; for(; i; i-=i&-i) res += bit[i]; return res;} bool V(int i){ return 0 <= i && i <= n;} signed main(){ scanf("%d %d %lld %lld %lld", &n, &q, t+0, t+1, a+0); for(int i = 1; i<=n; ++i){ scanf("%lld", a+i); d[i] = t[a[i-1] >= a[i]] * (a[i-1] - a[i]); sum += d[i]; } while(q--){ int l, r; ll v; scanf("%d %d %lld", &l, &r, &v); upd(l, +v); upd(r+1, -v); L[0] = a[l-1] + qry(l-1); L[1] = a[l] + qry(l); R[0] = a[r] + qry(r); R[1] = a[r+1] + qry(r+1); if(V(l-1)){ sum -= d[l]; d[l] = t[L[0] >= L[1]] * (L[0] - L[1]); sum += d[l]; } if(V(r+1)){ sum -= d[r+1]; d[r+1] = t[R[0] >= R[1]] * (R[0] - R[1]); sum += d[r+1]; } printf("%lld\n", sum); } }

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d %d %lld %lld %lld", &n, &q, t+0, t+1, a+0);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%lld", a+i);
      |   ~~~~~^~~~~~~~~~~~~
foehn_phenomena.cpp:18:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   int l, r; ll v; scanf("%d %d %lld", &l, &r, &v);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...