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"
using namespace std;
using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;
#define sz(v) ((int)v.size())
#define pb push_back
#define pry cout << "YES\n"
#define prn cout << "NO\n"
#define endl '\n'
#define fst first
#define scn second
/* #define ONPC */
using vi = vector<int>;
/* struct lenes_aint { */
/* int n; */
/* vi c; */
/* vector<ll> t, len; */
/* */
/* lenes_aint(vi &_c) { */
/* c = _c; */
/* n = sz(c); */
/* len.assign(4*n, 0); */
/* t.assign(4*n, 0); */
/* } */
/* */
/* void */
/* impinge(int i, int l, int r, int tl, int tr, int v) */
/* { */
/* int mid = (l+r)>>1; */
/* if (l > tr || r < tl) return; */
/* if (l >= tl && r <= tr) { */
/* len[i] += v; */
/* len[i] = max(len[i],0ll); */
/* return; */
/* } */
/* */
/* if (l == r) return; */
/* impinge(i<<1,l,mid,tl,tr,v); */
/* impinge(i<<1|1,mid+1,r,tl,tr,v); */
/* return; */
/* } */
/* */
/* void */
/* impinge_tot(int i, int l, int r) */
/* { */
/* */
/* return; */
/* } */
/* void impinge_tot() { } */
/* }; */
struct sump {
vector<ll> t;
vector<ll> p;
int n;
sump(int _n) {
n = _n;
t.assign(n+1,0);
p.assign(n+1,0);
}
void
add(int l, int r, int v)
{
t[l] += v;
t[r+1] -= v;
return;
}
void
gen()
{
for (int i = 0; i < n+1; ++i) {
if (i) p[i] = p[i-1];
p[i] += t[i];
}
return;
}
};
vi
sub2(vi &c, vi &l, vi &r, vi &v)
{
int n = sz(c);
int q = sz(l);
vi ans;
sump tr(n);
for (int j = 0; j < q; ++j) {
tr.add(l[j], r[j], v[j]);
}
tr.gen();
for (int i = 0; i < n; ++i) {
ll val = tr.p[i];
val = max(val,0ll);
val = min(val,(ll)c[i]);
ans.pb(val);
}
return ans;
}
vi
sub1(vi &c, vi &l, vi &r, vi &v)
{
int n = sz(c);
int q = sz(l);
vi ans;
ll val;
for (int i = 0; i < n; ++i) {
val = 0;
for (int j = 0; j < q; ++j) {
if (i < l[j] || i > r[j])
continue;
val += (ll)v[j];
val = min(val,(ll)c[i]);
val = max(val,0ll);
}
ans.pb(val);
}
return ans;
}
vi
distribute_candies(vi c, vi l, vi r, vi v)
{
int n = sz(c);
int q = sz(l);
if (n < 3e3 && q < 3e3)
return sub1(c,l,r,v);
return sub2(c,l,r,v);
vi tans;
for (int i = 0; i < n; ++i)
tans.pb(69);
return tans;
}
#ifdef ONPC
void
solve()
{
int n, q;
cin >> n >> q;
vector<int> c(n);
for (int i = 0; i < n; ++i)
cin >> c[i];
vector<int> l(q), r(q), v(q);
for (int i = 0; i < q; ++i)
cin >> l[i] >> r[i] >> v[i];
vi ans = distribute_candies(c,l,r,v);
for (int i = 0; i < sz(ans); ++i) {
cout << ans[i] << ' ';
}
cout << endl;
}
int32_t
main(int argc, char **argv)
{
if (argc >= 2) {
freopen(argv[1], "r", stdin);
} else
ios_base::sync_with_stdio(0);cin.tie(0);
int t = 1;
/* cin >> t; */
while(t--)
solve();
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |