Submission #1159986

#TimeUsernameProblemLanguageResultExecution timeMemory
1159986hainam2k9Foehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
95 ms6472 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 2e5+5; const string NAME = ""; int n,q,s,t,a[MAXN]; ll bit[MAXN],cur=0; void update(int pos, int val){ while(pos<=n) bit[pos]+=val, pos+=pos&-pos; } ll sum(int pos){ ll rs=0; while(pos>0) rs+=bit[pos], pos-=pos&-pos; return rs; } ll cost(ll L, ll R){ if(L<R) return -s*(R-L); return t*(L-R); } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> q >> s >> t; for(int i = 0; i<=n; ++i){ cin >> a[i]; if(i==0) continue; update(i,a[i]-a[i-1]); cur+=cost(a[i-1],a[i]); } while(q--){ int l,r,x; cin >> l >> r >> x; cur-=cost(sum(l-1),sum(l)); if(r<n) cur-=cost(sum(r),sum(r+1)); update(l,x), update(r+1,-x); cur+=cost(sum(l-1),sum(l)); if(r<n) cur+=cost(sum(r),sum(r+1)); cout << cur << "\n"; } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:39:45: note: in expansion of macro 'fo'
   39 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
foehn_phenomena.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:39:45: note: in expansion of macro 'fo'
   39 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...