제출 #114105

#제출 시각아이디문제언어결과실행 시간메모리
114105alexpetrescuFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
488 ms14924 KiB
#include <cstdio> //FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w"); #define fin stdin #define fout stdout #define ll long long #define MAXN 200009 #define MAXP 530000 int n, s, t, left, right, val, v[MAXN]; ll aint[MAXP]; void update(int p, int st, int dr) { if (left <= st && dr <= right) aint[p] += val; else { int m = (st + dr) / 2; if (left <= m) update(2 * p, st, m); if (m < right) update(2 * p + 1, m + 1, dr); } } inline ll query(int poz) { if (poz > n) poz = n; int p = 1, st = 0, dr = n; ll ans = v[poz]; while (st < dr) { ans += aint[p]; int m = (st + dr) / 2; if (poz <= m) dr = m, p = 2 * p; else st = m + 1, p = 2 * p + 1; } return ans + aint[p]; } inline ll cost(ll a, ll b) { if (a < b) return (a - b) * s; else return (a - b) * t; } inline ll calc(int l, int r) { return cost(query(l - 1), query(l)) + cost(query(r), query(r + 1)); } int main() { int q; fscanf(fin, "%d%d%d%d", &n, &q, &s, &t); ll ans = 0; for (int i = 0; i <= n; i++) { fscanf(fin, "%d", &v[i]); ans += cost(v[i - 1], v[i]); } for (int i = 1; i <= q; i++) { fscanf(fin, "%d%d%d", &left, &right, &val); ans -= calc(left, right); update(1, 0, n); ans += calc(left, right); fprintf(fout, "%lld\n", ans); } fclose(fin); fclose(fout); return 0; }

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

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:54:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "%d%d%d%d", &n, &q, &s, &t);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:58:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf(fin, "%d", &v[i]);
         ~~~~~~^~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:63:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf(fin, "%d%d%d", &left, &right, &val);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...