Submission #706401

#TimeUsernameProblemLanguageResultExecution timeMemory
706401Alihan_8Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
169 ms13128 KiB
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q, S, _T; cin >> n >> q >> S >> _T; vector <int> p(n+1); for ( auto &i: p ) cin >> i; vector <int> bit(n+1); auto upd = [&](int i, int val){ for (; i <= n; i += i&-i ) bit[i] += val; }; auto get = [&](int i){ int cnt = 0; for (; i > 0; i -= i&-i ) cnt += bit[i]; return cnt; }; int cnt = 0; for ( int i = 1; i <= n; i++ ){ if ( p[i-1] < p[i] ) cnt -= S*(p[i]-p[i-1]); else cnt += _T*(-p[i]+p[i-1]); upd(i, p[i]), upd(i+1, -p[i]); } while ( q-- ){ int l, r, x; cin >> l >> r >> x; if ( get(l) > get(l-1) ) cnt += S*(get(l)-get(l-1)); else cnt -= _T*(-get(l)+get(l-1)); if ( r+1 <= n ){ if ( get(r+1) > get(r) ) cnt += S*(get(r+1)-get(r)); else cnt -= _T*(get(r)-get(r+1)); } upd(l, x), upd(r+1, -x); if ( get(l) > get(l-1) ) cnt -= S*(get(l)-get(l-1)); else cnt += _T*(-get(l)+get(l-1)); if ( r+1 <= n ){ if ( get(r+1) > get(r) ) cnt -= S*(get(r+1)-get(r)); else cnt += _T*(get(r)-get(r+1)); } cout << cnt << ln; } cout << '\n'; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'void IO(std::string)':
foehn_phenomena.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...