제출 #38043

#제출 시각아이디문제언어결과실행 시간메모리
38043MatheusLealVFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
313 ms5140 KiB
#include <bits/stdc++.h> #define inf 200000000000000000LL #define N 200050 using namespace std; typedef long long ll; int n, q; ll A[N], bit[N], ans, S, T; void upd(int l, int r, int x) { if(1 <= l && l <= n + 1) for(int i = l; i < N; i += (i&-i)) bit[i] += x; if(1 <= r + 1&& r + 1 <= n + 1) for(int i = r + 1; i < N; i += (i&-i)) bit[i] -= x; } ll query(int x) { ll aux = 0; if(x <= 0 || x > n + 1) return inf; for(int i = x; i > 0; i -= (i&-i)) aux += bit[i]; return aux; } int32_t main() { scanf("%d %d %lld %lld", &n, &q, &S, &T); for(int i = 1; i <= n + 1; i++) scanf("%lld", &A[i]), upd(i, i, A[i]); for(int i = 1; i <= n; i++) ans += (A[i] <= A[i + 1] ? (- A[i + 1] + A[i])*S : (A[i] - A[i + 1])*T); for(int i = 1; i <= q; i++) { int li, ri; ll xi, dl = 0, dr = 0; scanf("%d %d %lld", &li, &ri, &xi); li ++, ri ++; ll Hl = query(li), Hr = query(ri), H_depois = query(ri + 1), H_antes = query(li - 1); upd(li, ri, xi); if(H_antes != inf && H_antes <= Hl) dl -= abs(Hl - H_antes)*S ; else if(H_antes != inf) dl += abs(Hl - H_antes)*T; if(Hr <= H_depois && H_depois != inf) dr -= abs(H_depois - Hr)*S ; else if(H_depois != inf) dr += abs(H_depois - Hr)*T; ans = ans - dl - dr; Hl += xi, Hr += xi; dl = 0, dr = 0; if(H_antes <= Hl&& H_antes != inf) dl -= abs(Hl - H_antes)*S ; else if(H_antes != inf) dl += abs(Hl - H_antes)*T; if(Hr <= H_depois && H_depois != inf) dr -= abs(H_depois - Hr)*S ; else if(H_depois != inf) dr += abs(H_depois - Hr)*T; ans += dl + dr; printf("%lld\n", ans); } }

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

foehn_phenomena.cpp: In function 'int32_t main()':
foehn_phenomena.cpp:31:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %lld %lld", &n, &q, &S, &T);
                                          ^
foehn_phenomena.cpp:33:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n + 1; i++) scanf("%lld", &A[i]), upd(i, i, A[i]);
                                                                       ^
foehn_phenomena.cpp:43:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %lld", &li, &ri, &xi);
                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...