제출 #339450

#제출 시각아이디문제언어결과실행 시간메모리
339450bigDuckFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
411 ms15744 KiB
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int n, q, s, t, a[200010]; int neg=0, pos=0; int seg[800010]; void lazy(int v){ seg[2*v]+=seg[v]; seg[2*v+1]+=seg[v]; seg[v]=0; return; } void update(int v, int tl, int tr, int l, int r, int x){ if(l>r){ return; } if( (l==tl) && (r==tr) ){ seg[v]+=x; return; } lazy(v); int mid=(tl+tr)>>1ll; update(v*2, tl, mid, l,min(r, mid), x); update(2*v+1, mid+1, tr, max(l, mid+1), r, x); } int query(int v, int tl, int tr, int p){ if(tl==tr){ return seg[v]; } int mid=(tl+tr)>>1ll; lazy(v); if(p<=mid){ return query(2*v, tl, mid, p); } else{ return query(2*v+1, mid+1, tr, p); } } int32_t main(){ INIT cin>>n>>q>>s>>t; for(int i=0; i<=n; i++){ cin>>a[i]; if(i>0){ if( (a[i])>a[i-1] ){ pos+=(a[i]-a[i-1]); } else{ neg+=(a[i]-a[i-1]); } } } //cout<<neg<<" "<<pos<<"\n"; while(q--){ int l, r, x; cin>>l>>r>>x; int a1=a1=( (l-1)>0 )?(query(1, 1, n, l-1)+a[l-1]):(0), a2=query(1, 1, n, l)+a[l]; int a3=query(1, 1, n, r)+a[r], a4=query(1, 1, n, min(r+1, n))+a[min(r+1, n)]; //cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<"\n"; if( (a2>a1) ){ pos-=a2-a1; } else{ neg-=a2-a1; } if( (a4>a3) ){ pos-=a4-a3; } else{ neg-=a4-a3; } update(1, 1, n, l, r, x); a1=( (l-1)>0 )?(query(1, 1, n, l-1)+a[l-1]):(0), a2=query(1, 1, n, l)+a[l]; a3=query(1, 1, n, r)+a[r], a4=query(1, 1, n, min(r+1, n))+a[min(r+1, n)]; if( (a2>a1) ){ pos+=a2-a1; } else{ neg+=a2-a1; } if( (a4>a3) ){ pos+=a4-a3; } else{ neg+=a4-a3; } //cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<"\n"; cout<<(t*(-neg)-s*pos)<<"\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int32_t main()':
foehn_phenomena.cpp:83:14: warning: operation on 'a1' may be undefined [-Wsequence-point]
   83 |     int a1=a1=( (l-1)>0 )?(query(1, 1, n, l-1)+a[l-1]):(0), a2=query(1, 1, n, l)+a[l];
      |            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...