이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890l
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-7) //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, q, s, t,A[MAXN],ans,fw[MAXN];
struct fen
{
void update(ll x, ll y, ll nv)
{
for(; x <= n; x+=x&(-x)) fw[x] += nv;
++y;
for(; y<=n; y+=y&(-y)) fw[y]-=nv;
}
ll sum(ll x) { /* point */ ll res = 0; for(; x; x-=x&(-x)) res += fw[x]; return res; }
} fen;
int main()
{
FAST
cin>>n>>q>>s>>t;
for(ll i = 0; i <= n; i++) cin>>A[i];
FOR(i,0,n)
{
if(A[i] < A[i+1]) ans -= (s*(A[i+1]-A[i]));
else ans += (t*(A[i]-A[i+1]));
}
FOR(i,1,n+1)fen.update(i,i,A[i]);
for(ll i=0;i<q;i++)
{
ll a, b, x;cin>>a>>b>>x;
{
ll b4 = fen.sum(a-1); ll aft = fen.sum(a);
if(b4 < aft) ans += (s*(aft-b4));
else ans -= (t*(b4-aft));
}
if(b != n)
{
ll b4 = fen.sum(b); ll aft = fen.sum(b+1);
if(b4 < aft) ans += (s*(aft-b4));
else ans -= (t*(b4-aft));
}
fen.update(a,b,x);
// if(a != 1)
{
ll b4 = fen.sum(a-1); ll aft = fen.sum(a);
if(b4 < aft) ans -= (s*(aft-b4));
else ans += (t*(b4-aft));
}
if(b != n)
{
ll b4 = fen.sum(b); ll aft = fen.sum(b+1);
if(b4 < aft) ans -= (s*(aft-b4));
else ans += (t*(b4-aft));
}
cout<<ans<<"\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... |