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;
const int maxn = 3e5 + 10;
const long long inf = 1e16;
long long a[maxn];
int arr[maxn];
int n;
struct node {
long long sum, lazyadd, lazyass;
long long left, right;
int pre, suf, opt, sz;
} t[maxn * 4], zero;
void addNode(node &p, long long val) {
p.left += val;
p.right += val;
p.sum += val * p.sz;
if(p.lazyass == inf) {
p.lazyadd += val;
} else {
p.lazyass += val;
}
}
void assNode(node &p, long long val) {
p.left = val;
p.right = val;
p.sum = val * p.sz;
p.opt = p.pre = p.suf = p.sz;
p.lazyadd = 0;
p.lazyass = val;
}
void pushdown(int c) {
int l = c << 1;
int r = l + 1;
if(t[c].lazyass == inf) {
addNode(t[l], t[c].lazyadd);
addNode(t[r], t[c].lazyadd);
} else {
assNode(t[l], t[c].lazyass);
assNode(t[r], t[c].lazyass);
}
t[c].lazyass = inf;
t[c].lazyadd = 0;
}
void merge(node &ans, node p, node q) {
ans.sum = p.sum + q.sum;
ans.left = p.left;
ans.right = q.right;
ans.pre = p.pre;
ans.suf = q.suf;
ans.opt = max(p.opt, q.opt);
if(p.pre == p.sz && p.right == q.left) ans.pre += q.pre;
if(q.suf == q.sz && q.left == p.right) ans.suf += p.suf;
if(p.right == q.left) ans.opt = max(ans.opt, p.suf + q.pre);
}
void add(int x, int y, long long val, int c = 1, int b = 1, int e = n) {
if(x <= b && e <= y) {
addNode(t[c], val);
return ;
}
if(y < b || e < x) return ;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
add(x, y, val, l, b, m);
add(x, y, val, r, m + 1, e);
merge(t[c], t[l], t[r]);
}
void assign(int x, int y, long long val, int c = 1, int b = 1, int e = n) {
if(x <= b && e <= y) {
assNode(t[c], val);
return ;
}
if(y < b || e < x) return ;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
assign(x, y, val, l, b, m);
assign(x, y, val, r, m + 1, e);
merge(t[c], t[l], t[r]);
}
long long getValue(int idx, int c = 1, int b = 1, int e = n) {
if(b == e) return t[c].sum;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(idx <= m) return getValue(idx, l, b, m);
else return getValue(idx, r, m + 1, e) + t[l].sum;
}
void build(int c = 1, int b = 1, int e = n) {
t[c].sz = e - b + 1;
t[c].lazyass = inf;
t[c].pre = t[c].suf = t[c].opt = t[c].sz;
if(b == e) {
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
build(l, b, m);
build(r, m + 1, e);
}
void patch(int l, int r, long long s, long long d) {
add(l, l, s);
add(l + 1, r, d);
if(r + 1 <= n) {
add(r + 1, r + 1, -(s + (r - l) * d));
}
}
void rewrite(int l, int r, long long s, long long d) {
long long last = getValue(r);
add(l, l, s - getValue(l));
assign(l + 1, r, d);
if(r + 1 <= n) {
add(r + 1, r + 1, last - (s + (r - l) * d));
}
}
node range(int x, int y, int c = 1, int b = 1, int e = n) {
if(x <= b && e <= y) {
return t[c];
}
if(y < b || e < x) return zero;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
node ans;
merge(ans, range(x, y, l, b, m), range(x, y, r, m + 1, e));
return ans;
}
int query(int l, int r) {
if(l == r) return 1;
return range(l + 1, r).opt + 1;
}
int main() {
int m;
scanf("%d %d", &n, &m);
build();
zero.left = -inf; zero.right = inf;
for(int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
add(i, i, arr[i] - arr[i - 1]);
}
for(int i = 1; i <= m; i++) {
int c, l, r, s, d;
scanf("%d %d %d", &c, &l, &r);
if(c == 1) {
scanf("%d %d", &s, &d);
patch(l, r, s, d);
} else if (c == 2) {
scanf("%d %d", &s, &d);
rewrite(l, r, s, d);
} else {
printf("%d\n", query(l, r));
}
}
return 0;
}
Compilation message (stderr)
Progression.cpp: In function 'int main()':
Progression.cpp:141:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:145:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
Progression.cpp:151:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &c, &l, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:153:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &s, &d);
~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:156:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &s, &d);
~~~~~^~~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |