이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 5010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
struct Fenwick_Tree
{
int bit_add[maxn],bit_sub[maxn];
void update(int u, int v, int val)
{
for (int i = u; i <= maxn; i += i & -i)
{
bit_add[i] += val;
bit_sub[i] += 1LL * (u - 1) * val;
}
for (int i = v; i <= maxn; i += i & -i)
{
bit_add[i] -= val;
bit_sub[i] -= 1LL * v * val;
}
}
void update(int u, int val)
{
update(u, u, val);
}
int get(int u)
{
if(u < 0) return 0;
int ans1 = 0, ans2 = 0;
for (int i = u; i; i -= i & -i)
{
ans1 += bit_add[i];
ans2 += bit_sub[i];
}
return u * ans1 - ans2;
}
int get(int l, int r)
{
return get(r) - get(l - 1);
}
} t1;
int a[maxn];
int n,q,s,t;
int ans;
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q >> s >> t;
fo(i,0,n)
{
cin >> a[i];
ans += ((a[i - 1] - a[i] < 0) ? s : t) * (a[i - 1] - a[i]);
}
fo(i,1,n) t1.update(i,i,a[i]);
while(q--)
{
int l,r,add;
cin >> l >> r >> add;
int val = ((t1.get(l - 1,l - 1) - t1.get(l,l) < 0) ? s : t) * (t1.get(l - 1,l - 1) - t1.get(l,l));
ans -= val;
if(r < n)
{
val = ((t1.get(r,r) - t1.get(r + 1,r + 1) < 0) ? s : t) * (t1.get(r,r) - t1.get(r + 1,r + 1));
ans -= val;
}
t1.update(max(l,1LL),r,add);
val = ((t1.get(l - 1,l - 1) - t1.get(l,l) < 0) ? s : t) * (t1.get(l - 1,l - 1) - t1.get(l,l));
ans += val;
// cout << val << ' ' << ans << "\n";
if(r < n)
{
val = ((t1.get(r,r) - t1.get(r + 1,r + 1) < 0) ? s : t) * (t1.get(r,r) - t1.get(r + 1,r + 1));
ans += val;
}
cout << ans;
en;
// fo(i,1,n) cout << t1.get(i,i) << ' ';
// en;
}
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp:81:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
81 | main()
| ^~~~
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |