#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define FOR(i , a , b) for(int i = (a) , _b = (b); i <= _b; ++i)
#define sz(x) (int)(x).size()
#define BIT(mask , x) (((mask) >> (x)) & (1))
#define MASK(x) ((LL)(1)<<(x))
#define TIME_USED cerr << endl << "TIME LAPSED : " << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl;
template<class T1 , class T2>
bool maximize(T1 &a , T2 b){
if (a < b) return a = b , true; else return false;
}
template<class T1 , class T2>
bool minimize(T1 &a , T2 b){
if (a > b) return a = b , true; else return false;
}
template<class T>
void compress(vector<T>&data){
sort(data.begin() , data.end());
data.resize(unique(data.begin() , data.end()) - data.begin());
}
template<class T1 , class T2>
T2 Find(const vector<T1>&data , T2 y){
return upper_bound(data.begin() , data.end() , y) - data.begin();
}
const int N = (int) 3e5;
const LL inf = (LL) 1e18;
int n , q;
LL a[N + 2] = {};
struct QUERY{
int t;
int l , r , s , c;
void read(){
cin >> t;
if (t == 1 || t == 2) cin >> l >> r >> s >> c;
else cin >> l >> r;
return;
}
} queri[N + 2];
namespace subtask1{
bool check(){
return n <= 1e3 && q <= 1e3;
}
void patch(int l , int r , int s , int c){
FOR(i , l , r) a[i] += (LL)s + (LL)(i - l) * c;
return;
}
void rewrite(int l , int r , int s , int c){
FOR(i , l , r) a[i] = (LL) s + (LL)(i - l) * c;
return;
}
int calc(int l , int r){
if (r - l + 1 <= 2) return r - l + 1;
int ans = 2;
for(int i = l + 1; i <= r; ++i){
int t = a[i] - a[i - 1] , ptr = i;
while (ptr <= r && a[ptr] - a[ptr - 1] == t) ++ptr;
ans = max(ans , ptr - i + 1);
i = ptr - 1;
}
return ans;
}
void main_code(){
for(int i = 1; i <= q; ++i){
if (queri[i].t == 1) patch(queri[i].l , queri[i].r , queri[i].s , queri[i].c);
if (queri[i].t == 2) rewrite(queri[i].l , queri[i].r , queri[i].s , queri[i].c);
if (queri[i].t == 3) cout << calc(queri[i].l , queri[i].r) << '\n';
}
}
}
namespace subtask2{
bool check(){
FOR(i , 1 , q) if (queri[i].t != 3) return false;
return true;
}
struct Node{
int length;
int prefix_length , suffix_length;
int tot;
LL prefix_value , suffix_value;
LL max_value , min_value;
Node(){
length = suffix_length = prefix_length = 0;
max_value = -inf , min_value = inf;
prefix_value = 0 , suffix_value = 0;
tot = 0;
return;
}
};
Node st[N * 4 + 2];
Node operator + (Node a , Node b){
Node c = Node();
c.prefix_value = a.prefix_value , c.suffix_value = b.suffix_value;
c.prefix_length = a.prefix_length , c.suffix_length = b.suffix_length;
c.max_value = max(a.max_value , b.max_value) ,
c.min_value = min(a.min_value , b.min_value);
c.length = a.length + b.length;
c.tot = max(a.tot , b.tot);
bool same_a = false , same_b = false;
same_a = (a.max_value == a.min_value);
same_b = (b.min_value == b.max_value);
if (same_a && b.prefix_value == a.max_value) {
c.prefix_length = a.length + b.prefix_length;
}
if (same_b && a.suffix_value == b.max_value){
c.suffix_length = b.length + a.suffix_length;
}
c.tot = max(c.tot , max(c.suffix_length , c.prefix_length));
return c;
}
LL lst[N + 2] = {};
void build(int id , int l , int r){
if (l == r) {
st[id].tot = st[id].prefix_length = st[id].suffix_length = st[id].length = 1;
st[id].max_value = st[id].min_value = lst[l];
st[id].suffix_value = st[id].prefix_value = lst[l];
}
else{
int m = (l + r) / 2;
build(id * 2 , l , m) ,
build(id * 2 + 1 , m + 1 , r);
st[id] = st[id * 2] + st[id * 2 + 1];
}
}
Node Get(int id , int l , int r , int u , int v){
if (l > v || r < u) return Node();
if (u <= l && r <= v) return st[id];
int m = (l + r) / 2;
return Get(id * 2 , l , m , u , v) + Get(id * 2 + 1 , m + 1 , r , u , v);
}
LL ans(int l , int r){
Node g = Get(1 , 1 , n - 1 , l , r);
// cout << g.max_value << ' ' << g.min_value << '\n';
return g.tot + 1;
}
void main_code(){
for(int i = 2; i <= n; ++i) lst[i - 1] = a[i] - a[i - 1];
build(1 , 1 , n - 1);
for(int i = 1; i <= q; ++i){
int l = queri[i].l , r = queri[i].r;
cout << min((LL)r - l + 1 , ans(l , r)) << '\n';
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0) ; cout.tie(0);
#define name "main"
if (fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
cin >> n >> q;
FOR(i , 1 , n) cin >> a[i];
FOR(i , 1 , q) queri[i].read();
if (subtask2::check()) return subtask2::main_code() , 0;
TIME_USED;
}
Compilation message (stderr)
Progression.cpp: In function 'int main()':
Progression.cpp:176:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
176 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:177:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
177 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |