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 = 2e5 + 10;
long long a[maxn];
int arr[maxn];
int n;
long long getValue(int idx) {
long long ans = 0;
for(int i = 1; i <= idx; i++) {
ans += a[i];
}
return ans;
}
void add(int l, int r, long long d) {
for(int i = l; i <= r; i++) a[i] += d;
}
void assign(int l, int r, long long d) {
for(int i = l; i <= r; i++) a[i] = d;
}
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));
}
}
int query(int l, int r) {
if(l == r) return 1;
int cnt = 1;
int ans = 1;
for(int i = l + 2; i <= r; i++) {
if(a[i] == a[i - 1]) {
++cnt;
ans = max(ans, cnt);
} else {
cnt = 1;
}
}
return ans + 1;
}
int main() {
int m;
scanf("%d %d", &n, &m);
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:52: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:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
Progression.cpp:59: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:61: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:64: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... |