제출 #224197

#제출 시각아이디문제언어결과실행 시간메모리
224197Ruxandra985Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
380 ms15728 KiB
#include <bits/stdc++.h> using namespace std; long long aint[800010] , v[200010]; void build (long long nod , long long st , long long dr){ long long mid = (st + dr)/2; if (st == dr){ aint[nod] = v[st]; return; } build (2 * nod , st , mid); build (2 * nod + 1 , mid + 1 , dr); } void update (long long nod , long long st , long long dr , long long l , long long r , long long val){ long long mid = (st + dr)/2; if (l <= st && dr <= r){ aint[nod] += val; return; } aint[2 * nod] += aint[nod]; aint[2 * nod + 1] += aint[nod]; aint[nod] = 0; if (l <= mid) update (2 * nod , st , mid , l , r , val); if (mid + 1 <= r) update (2 * nod + 1 , mid + 1 , dr , l , r , val); } long long query (long long nod , long long st , long long dr , long long p){ long long mid = (st + dr)/2; if (st == dr){ return aint[nod]; } aint[2 * nod] += aint[nod]; aint[2 * nod + 1] += aint[nod]; aint[nod] = 0; if (p <= mid) return query (2 * nod , st , mid , p); else return query (2 * nod + 1 , mid + 1 , dr , p); } int main() { FILE *fin = stdin; FILE *fout = stdout; long long n , i , q , s , t , sol , p1 , p2 , q1 , q2 , l , r , x; fscanf (fin,"%lld%lld%lld%lld",&n,&q,&s,&t); /// temp scade cu s / unitate cand alt creste /// temp creste cu t / unitate cand alt scade for (i = 0 ; i <= n ; i++){ fscanf (fin,"%lld",&v[i]); } build (1 , 0 , n); sol = 0; for (i = 0 ; i < n ; i++){ if (v[i] < v[i + 1]) sol = sol - s * (v[i + 1] - v[i]); else sol = sol + t * (v[i] - v[i + 1]); } for (;q;q--){ fscanf (fin,"%lld%lld%lld",&l,&r,&x); p1 = query (1 , 0 , n , l - 1); p2 = query (1 , 0 , n , l); if (p1 < p2) sol = sol + s * (p2 - p1); else sol = sol - t * (p1 - p2); q1 = query (1 , 0 , n , r); q2 = query (1 , 0 , n , r + 1); if (r != n){ if (q1 < q2) sol = sol + s * (q2 - q1); else sol = sol - t * (q1 - q2); } update (1 , 0 , n , l , r , x); p2 += x; q1 += x; if (p1 < p2) sol = sol - s * (p2 - p1); else sol = sol + t * (p1 - p2); if (r != n){ if (q1 < q2) sol = sol - s * (q2 - q1); else sol = sol + t * (q1 - q2); } fprintf (fout,"%lld\n",sol); } return 0; }

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

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:67:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%lld%lld%lld%lld",&n,&q,&s,&t);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:72:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lld",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:86:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lld%lld%lld",&l,&r,&x);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...