이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sts(v) stable_sort(v.BE, v.E)
#define Rsts(v) stable_sort(v.rBE, v.rE)
#define rev(v) reverse(v.BE, v.E)
#define BE begin()
#define rBE rbegin()
#define E end()
#define rE rend()
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
using namespace std;
using ll = long long;
struct ABI{
vector<ll> abi;
ABI(int n){
abi.resize(n + 1);
}
void updt(int i, int val){
for(; i < (int)abi.size(); i += i & -i)
abi[i] += val;
}
void range(int l, int r, int val){
updt(l, val);
updt(r + 1, -val);
}
ll query(int i){
ll sum = 0;
for(; i > 0; i -= i & -i)
sum += abi[i];
return sum;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, Q, S, T; cin >> n >> Q >> S >> T;
vector<ll> v(n + 1);
for(int i = 0; i <= n; i++)
cin >> v[i];
bool type[n + 1];
int x = 0, y = 0, last[n + 1];
for(int i = 1; i <= n; i++){
last[i] = v[i] - v[i - 1];
type[i] = last[i] > 0;
if(type[i]) x += last[i];
else y += abs(last[i]);
}
// cout << x << ' ' << y << '\n';
ABI abi(n);
while(Q--){
int l, r, X; cin >> l >> r >> X;
abi.range(l, r, X);
ll i = v[l] + abi.query(l), _i = v[l - 1] + abi.query(l - 1);
if(type[l])
x -= last[l];
else
y -= abs(last[l]);
last[l] = i - _i;
type[l] = last[l] > 0;
if(type[l])
x += last[l];
else
y += abs(last[l]);
if(r < n){
r++;
i = v[r] + abi.query(r);
_i = v[r - 1] + abi.query(r - 1);
if(type[r])
x -= last[r];
else
y -= abs(last[r]);
last[r] = i - _i;
type[r] = last[r] > 0;
if(type[r])
x += last[r];
else
y += abs(last[r]);
}
cout << y * T - x * S << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |