이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
struct FenwickTree{
ll n;
vector<ll> a;
FenwickTree(ll _n){
n = _n;
a.resize(n+1);
}
void update(ll i, ll v){
while(i <= n){
a[i] += v;
i += LASTBIT(i);
}
}
ll get(ll i){
ll ans = 0;
while(i > 0){
ans += a[i];
i -= LASTBIT(i);
}
return ans;
}
};
const ll N = 2e5 + 69;
ll n, q;
ll s, t;
ll dt[N];
FenwickTree bit(N);
ll ans= 0;
void update(ll l, ll r, ll val){
ans -= dt[l];
ans -= dt[r+1];
bit.update(l, val);
bit.update(r + 1, -val);
dt[l] = bit.get(l) - bit.get(l-1);
if (dt[l] > 0) dt[l] *= s;
else dt[l] *= t;
dt[r+1] = bit.get(r+1) - bit.get(r);
if (dt[r+1] > 0) dt[r+1] *= s;
else dt[r+1] *= t;
ans += dt[l]; ans += dt[r+1];
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t;
vector<ll> a(n+1);
for(ll i= 0; i<=n; ++i) cin >> a[i];
for(ll i = 1; i<=n; ++i){
update(i, i, a[i]);
}
while(q--){
ll l, r, x; cin >> l >> r >> x;
update(l, r, x);
cout << -(ans - dt[n+1]) << "\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... |