# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
364238 | Rainbowbunny | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 195 ms | 13164 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
int n, q;
long long S, T;
long long BIT[200005], A[200005];
void Add(int node, long long val)
{
for(node; node <= n + 1; node += node & -node)
{
BIT[node] += val;
}
}
long long Get(int node)
{
long long ans = 0;
for(node; node > 0; node -= node & -node)
{
ans += BIT[node];
}
return ans;
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin >> n >> q >> S >> T;
for(int i = 1; i <= n + 1; i++)
{
std::cin >> A[i];
Add(i, A[i]);
Add(i + 1, -A[i]);
}
long long ans = 0;
for(int i = 1; i <= n; i++)
{
long long tmp = A[i + 1] - A[i];
if(tmp > 0)
{
ans -= tmp * S;
}
else
{
ans -= tmp * T;
}
}
while(q--)
{
int l, r;
long long x;
std::cin >> l >> r >> x;
l++; r++;
long long value = Get(l) - Get(l - 1);
if(value > 0)
{
ans += value * S;
}
else
{
ans += value * T;
}
value += x;
if(value > 0)
{
ans -= value * S;
}
else
{
ans -= value * T;
}
if(r != n + 1)
{
value = Get(r + 1) - Get(r);
if(value > 0)
{
ans += value * S;
}
else
{
ans += value * T;
}
value -= x;
if(value > 0)
{
ans -= value * S;
}
else
{
ans -= value * T;
}
}
Add(l, x);
Add(r + 1, -x);
std::cout << ans << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |