Submission #112306

#TimeUsernameProblemLanguageResultExecution timeMemory
112306MercenaryFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
163 ms13176 KiB
#include<bits/stdc++.h> using namespace std; #define taskname "A" #define pb push_back #define mp make_pair #ifndef LOCAL #define cerr if(0)cout #endif typedef long double ld; typedef long long ll; typedef pair<int,int> ii; const int maxn = 2e5 + 5; int s , t , n , q; ll a[maxn] , b[maxn]; void update(int x , int delta){ for( ; x <= n ; x += x & -x) a[x] += delta; } ll query(int x){ ll res = 0; for( ; x > 0 ; x &= x - 1) res += a[x]; return res; } ll get(ll pre , ll now , ll add){ ll res = 0; if(pre <= now){ res += (ll)s * (now - pre); }else res -= (ll)t * (pre - now); now += add; if(pre <= now){ res -= (ll)s * (now - pre); }else res += (ll)t * (pre - now); return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n >> q >> s >> t; ll res = 0; for(int i = 0 ; i <= n ; ++i){ cin >> b[i]; if(i > 0){ update(i,b[i]-b[i - 1]); if(b[i] >= b[i - 1]){ res -= s * (ll)(b[i] - b[i - 1]); // cout << i << " "; }else{ res += t * (ll)(b[i - 1] - b[i]); } } // cout << res << endl; } for(int i = 1 ; i <= q ; ++i){ int x , y , val;cin >> x >> y >> val; res += get(query(x - 1) , query(x) , val); if(y != n)res += get(query(y) , query(y + 1) , -val); update(x,val); update(y + 1 , -val); cout << res << '\n'; } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:49:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:50:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...