이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MEM 200005
#define sanic ios_base::sync_with_stdio(0)
#define MOD 1000000
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 1e13+7;
ll t,n,m,x,y;
ll tree[4*MEM], a[MEM], c[MEM];
ll init(ll pos, ll val, ll idx, ll s, ll e){
if(s>idx || idx>e) return tree[pos];
if(s==e) return tree[pos] = val;
ll mid = (s+e)/2;
return tree[pos] = init(pos*2, val, idx, s, mid)+init(pos*2+1, val, idx, mid+1, e);
}
ll query(ll nd, ll l, ll r, ll s, ll e){
if(l>e || s>r) return 0;
if(l<=s && e<=r) return tree[nd];
ll mid = (s+e)/2;
return query(nd*2, l, r, s, mid)+query(nd*2+1, l, r, mid+1, e);
}
int main() {
sanic; cin.tie(0); cout.tie(0);
cin >> n >> m >> x >> y;
for(int i=0; i<=n; i++){
cin >> a[i];
if(i) c[i] = a[i-1]-a[i];
}
for(int i=1; i<=n; i++)
init(1, c[i]*(c[i]>0 ? y:x), i, 1, n);
while(m--){
ll q1,q2,q3;
cin >> q1 >> q2 >> q3;
c[q1] -= q3;
c[q2+1] += q3;
init(1, c[q1]*(c[q1]>0 ? y:x), q1, 1, n);
init(1, c[q2+1]*(c[q2+1]>0 ? y:x), q2+1, 1, n);
cout << query(1, 1, n, 1, n) <<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |