제출 #1179869

#제출 시각아이디문제언어결과실행 시간메모리
1179869Paz15Foehn Phenomena (JOI17_foehn_phenomena)C++20
30 / 100
12 ms1860 KiB
//fast #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(n) for(int i = 0 ; i<n ; i++) #define all(x) x.begin(),x.end() #define pb push_back const int base = 2e5+7; const int tbase = (1<<18); ll tree[tbase]; ll alt[base]; ll s,t,n; void dod(int a, int b, int x){ a+=base-1; b+=base+1; while (b-a>1){ if (a%2==0) tree[a+1]+=x; if (b%2==1) tree[b-1]+=x; a/=2; b/=2; } } int zap(int x){ ll w = alt[x]; x+=base; while (x>=1){ w+=tree[x]; x/=2; } return w; } ll update(int l, int r){ ll w = 0; if (l!=0){ ll a = zap(l-1); ll b = zap(l); if (a>b) w+=(a-b)*t; else w+=(a-b)*s; } if (r!=n){ ll a = zap(r); ll b = zap(r+1); if (a>b) w+=(a-b)*t; else w+=(a-b)*s; } return w; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int q; cin >> n >> q >> s >> t; ll sum = 0; cin >> alt[0]; rep(n){ cin >> alt[i+1]; if (alt[i]>alt[i+1]){ sum+=(alt[i]-alt[i+1])*t; }else sum+=(alt[i]-alt[i+1])*s; } while (q--){ int l,r,x; cin >> l >> r >> x; sum-=update(l,r); dod(l,r,x); sum+=update(l,r); cout << sum << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...