제출 #220578

#제출 시각아이디문제언어결과실행 시간메모리
220578kshitij_sodaniFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
559 ms8952 KiB
#include <algorithm> #include <cassert> #include <cstring> #include <iostream> /* #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <functional> #include <iomanip> #include <iterator> #include <limits> #include <list> #include <numeric> #include <random> #include <ratio> #include <sstream> #include <utility> #include <bitset> #include <deque> #include <queue> #include <map> #include <vector> #include <unordered_map> #include <unordered_set> #include <stack> #include <string> #include <set>*/ using namespace std; #define a first #define b second #define pb push_back typedef long long llo; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); llo n,q,s,t; cin>>n>>q>>s>>t; n+=1; llo aa[n]; llo tot=0; llo bb[n][2]; for(llo i=0;i<n;i++){ cin>>aa[i]; bb[i][0]=0; bb[i][1]=0; if(i>0){ if(aa[i]>aa[i-1]){ tot-=s*abs(aa[i]-aa[i-1]); } else{ tot+=t*abs(aa[i]-aa[i-1]); } } } // cout<<tot<<endl; for(llo i=0;i<q;i++){ llo l,r,x; cin>>l>>r>>x; if(l>0){ if(aa[l]+bb[l-1][1]<bb[l][0]+aa[l-1]){ tot-=t*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1]))); } else{ tot+=s*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1]))); } bb[l-1][1]+=x; if(aa[l]+bb[l-1][1]<bb[l][0]+aa[l-1]){ tot+=t*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1]))); } else{ tot-=s*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1]))); } } if(r<n-1){ if(aa[r]+bb[r+1][0]<bb[r][1]+aa[r+1]){ tot+=s*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1]))); } else{ tot-=t*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1]))); } bb[r+1][0]+=x; if(aa[r]+bb[r+1][0]<bb[r][1]+aa[r+1]){ tot-=s*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1]))); } else{ tot+=t*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1]))); } } cout<<tot<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...