Submission #242081

#TimeUsernameProblemLanguageResultExecution timeMemory
242081michaoFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
155 ms9720 KiB
#include <bits/stdc++.h> //#define ll long long int #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; int n,q,s,t; int ans=0; const int MAX=1<<18; int tree[2*MAX]; int tab[MAX]; int dp[MAX]; void update(int u,int v,int c) { for (u+=MAX,v+=MAX;u<v;u>>=1,v>>=1) { if (u&1)tree[u++]+=c; if (v&1)tree[--v]+=c; } } int query(int u) { int sum=u; for (u+=MAX;u>0;u>>=1)sum+=tree[u]; return sum; } int32_t main() { BOOST; cin>>n>>q>>s>>t; for (int i=0;i<=n;i++)cin>>tab[i],update(i,i+1,tab[i]); dp[0]=0; for (int i=1;i<=n;i++) { if (tab[i]>tab[i-1])dp[i]=dp[i-1]-s*(tab[i]-tab[i-1]); else dp[i]=dp[i-1]+t*(tab[i-1]-tab[i]); //cout<<"TERAZ "<<i<<" "<<dp[i]<<"\n"; } ans=dp[n]; for (int z=0;z<q;z++) { int l,r,c; cin>>l>>r>>c; update(l,r+1,c); ans+=(r-l+1)*c; cout<<ans<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...