이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 2e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
vector<int> seg(MAXN<<2);
vector<int> lazy(MAXN<<2);
vector<int> niz(MAXN);
void build(int nod, int l, int r)
{
if(l==r)
{
seg[nod] = niz[l];
return;
}
int mid = l+r>>1;
build(nod<<1, l, mid);
build(nod<<1|1, mid+1,r);
seg[nod] = seg[nod<<1]+seg[nod<<1|1];
}
void push(int nod, int tl, int tr)
{
if(lazy[nod] == 0)return;
if(tl!=tr)
{
lazy[nod<<1] = lazy[nod];
lazy[nod<<1|1] = lazy[nod];
}
seg[nod] += (tr-tl+1)*lazy[nod];
lazy[nod] = 0;
}
void update(int nod, int tl, int tr, int l, int r, int v)
{
push(nod, tl, tr);
if(tl>r || tr<l || tl>tr)return;
if(tl>=l && tr<=r)
{
lazy[nod]+=v;
push(nod, tl, tr);
return;
}
int mid = tl+tr>>1;
update(nod<<1,tl, mid, l, r, v);
update(nod<<1|1,mid+1, tr, l, r, v);
seg[nod] = seg[nod<<1]+seg[nod<<1|1];
}
int query(int nod, int tl, int tr, int l, int r)
{
push(nod,tl,tr);
if(tl > r || tr < l)return 0;
if(tl>=l && tr<=r)return seg[nod];
int mid = tl+tr>>1;
return query(nod<<1,tl, mid, l, r) + query(nod<<1|1, mid+1, tr, l, r);
}
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int n,q,s,t;
cin >> n >> q >> s >> t;
int delta = 0;
for(int i=0; i<=n; i++)cin >> niz[i];
for(int i=0; i<n; i++)
{
if(niz[i] < niz[i+1])delta-=abs(niz[i]-niz[i+1])*s;
else delta+=abs(niz[i]-niz[i+1])*t;
}
build(1,1,n);
while(q--)
{
int a,b,x;
cin >> a >> b >> x;
//a++;b++;
if(a!=1)
{
int q1 = query(1,1,n,a,a);
int q2 = query(1,1,n,a-1,a-1);
if(q2<q1)delta+=abs(q1-q2)*s;
else delta-=abs(q1-q2)*t;
}
else
{
int q1 = query(1,1,n,a,a);
int q2 = 0;
if(q2<q1)delta+=abs(q1-q2)*s;
else delta-=abs(q1-q2)*t;
}
if(b!=n)
{
int q1 = query(1,1,n,b+1,b+1);
int q2 = query(1,1,n,b,b);
if(q2<q1)delta+=abs(q1-q2)*s;
else delta-=abs(q1-q2)*t;
}
update(1,1,n, a, b, x);
if(a!=1)
{
int q1 = query(1,1,n,a,a);
int q2 = query(1,1,n,a-1,a-1);
if(q2<q1)delta-=abs(q1-q2)*s;
else delta+=abs(q1-q2)*t;
}
else
{
int q1 = query(1,1,n,a,a);
int q2 = 0;
if(q2<q1)delta-=abs(q1-q2)*s;
else delta+=abs(q1-q2)*t;
}
if(b!=n)
{
int q1 = query(1,1,n,b+1,b+1);
int q2 = query(1,1,n,b, b);
if(q2<q1)delta-=abs(q1-q2)*s;
else delta+=abs(q1-q2)*t;
}
cout << delta << endl;
//cout << "NIZ: 0 ";
//for(int i=1; i<=n; i++)cout << query(1,1,n,i) << " ";
//cout << endl;
}
}
}
/*
3 3 1 1
0 5 2 1
1 2 -1
1 1 -4
1 1 2
*/
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'void build(long long int, long long int, long long int)':
foehn_phenomena.cpp:28:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = l+r>>1;
| ~^~
foehn_phenomena.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
foehn_phenomena.cpp:56:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid = tl+tr>>1;
| ~~^~~
foehn_phenomena.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int)':
foehn_phenomena.cpp:68:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int mid = tl+tr>>1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |