# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883617 | Yang8on | Sjeckanje (COCI21_sjeckanje) | C++14 | 1 ms | 2396 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 <bits/stdc++.h>
#define Yang8on Nguyen_Dinh_Son
#define sonphamay Nguyen_Dinh_Son
#define aothtday "Sjeckanje"
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define endl '\n'
#define pii pair<int, ll>
#define vi vector<int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define maxn 200005
#define maxm
#define maxx
#define mod 1000000007
#define base 311
#define ModHas 1000000003ll
#define gb(i, j) ((i >> j) & 1)
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r)(rng);
}
int n, q;
ll a[maxn], d[maxn];
struct dl
{
ll op_op, op_cl, cl_op, cl_cl;
void cb(dl x, dl y, int mid)
{
op_op = max(x.op_op + y.cl_op, x.op_cl + y.op_op);
op_cl = max(x.op_op + y.cl_cl, x.op_cl + y.op_cl);
cl_op = max(x.cl_op + y.cl_op, x.cl_cl + y.op_op);
cl_cl = max(x.cl_op + y.cl_op, x.cl_cl + y.op_cl);
if((d[mid] < 0 && d[mid + 1] < 0) || (d[mid] >= 0 & d[mid + 1] >= 0))
{
op_op = max(x.op_op, x.op_cl) + max(y.op_op, y.cl_op);
op_cl = max(x.op_op, x.op_cl) + max(y.op_cl, y.cl_cl);
cl_op = max(x.cl_op, x.cl_cl) + max(y.cl_op, y.op_op);
cl_cl = max(x.cl_op, x.cl_cl) + max(y.op_cl, y.cl_cl);
}
}
} st[4 * maxn];
void built(int id = 1, int l = 1, int r = n - 1)
{
if(l == r)
{
st[id].op_op = abs(d[l]);
return ;
}
int mid = (l + r) >> 1;
built(id * 2, l, mid);
built(id * 2 + 1, mid + 1, r);
st[id].cb(st[id * 2], st[id * 2 + 1], mid);
}
void update(int pos, int id = 1, int l = 1, int r = n - 1)
{
if(pos < l || r < pos) return ;
if(l == r)
{
st[id].op_op = abs(d[pos]);
return ;
}
int mid = (l + r) >> 1;
update(pos, id * 2, l, mid);
update(pos, id * 2 + 1, mid + 1, r);
st[id].cb(st[id * 2], st[id * 2 + 1], mid);
}
void solve()
{
cin >> n >> q;
fi(i, 1, n) cin >> a[i];
fi(i, 1, n - 1) d[i] = a[i] - a[i + 1];
built();
fi(_, 1, q)
{
int l, r;
ll x;
cin >> l >> r >> x;
if(l - 1 != 0)
{
d[l - 1] -= x;
update(l - 1);
}
if(r != n)
{
d[r] += x;
update(r);
}
cout << st[1].op_op << '\n';
}
// cout << max({st[1].op_op, st[1].op_cl, st[1].cl_op, st[1].cl_cl});
}
int main()
{
if(fopen(aothtday".inp", "r"))
{
freopen(aothtday".inp","r",stdin);
freopen(aothtday".out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int nTest = 1;
// cin >> nTest;
while(nTest --)
{
solve();
}
return 0;
}
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... |