이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define ll long long int
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,q,s,t;
int ans=0;
const int MAX=1<<18;
int tree[2*MAX];
int tab[MAX];
int dp[MAX];
void update(int u,int v,int c)
{
for (u+=MAX,v+=MAX;u<v;u>>=1,v>>=1)
{
if (u&1)tree[u++]+=c;
if (v&1)tree[--v]+=c;
}
}
int query(int u)
{
int sum=0;
for (u+=MAX;u>0;u>>=1)sum+=tree[u];
return sum;
}
int32_t main()
{
BOOST;
cin>>n>>q>>s>>t;
for (int i=0;i<=n;i++)cin>>tab[i],update(i,i+1,tab[i]);
dp[0]=0;
for (int i=1;i<=n;i++)
{
if (tab[i]>tab[i-1])dp[i]=dp[i-1]-s*(tab[i]-tab[i-1]);
else dp[i]=dp[i-1]+t*(tab[i-1]-tab[i]);
}
ans=dp[n];
for (int z=0;z<q;z++)
{
int l,r,c;
cin>>l>>r>>c;
//cout<<"ZAWARTOSC "<<z<<"\n";
//for (int i=0;i<=n;i++)cout<<query(i)<<" ";
//cout<<"\n";
int prevl=query(l);
int prevr=query(r);
update(l,r+1,c);
int nowl=query(l);
int nowr=query(r);
int ilel=query(l-1);
int iler=query(r+1);
int balans=0;
// pierwsza czesc dla lewego;
//if (z==2)cout<<"TERAZ "<<ilel<<" "<<prevl<<" "<<nowl<<"\n";
if (ilel>=prevl)balans-=(ilel-prevl)*t;
else balans+=(prevl-ilel)*s;
if (ilel>=nowl)balans+=(ilel-nowl)*t;
else balans-=(nowl-ilel)*s;
// druga czesc dla prawego
if (r!=n)
{
if (iler<=prevr)balans-=(prevr-iler)*t;
else balans+=(iler-prevr)*s;
if (iler<=nowr)balans+=(nowr-iler)*t;
else balans-=(iler-nowr)*s;
}
ans+=balans;
cout<<ans<<"\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... |