/**
* \author Nguyen Duc Kien
* \date 20/06/2021
*/
///Task name
#define TASK ""
///-------------------------------------------///
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int n, Q, f[maxn], g[maxn], ftree[maxn << 2], lftree[maxn << 2];
long long a[maxn];
struct query
{
int req, L, R, S, C;
void inp()
{
cin >> req >> L >> R;
if (req != 3) cin >> S >> C;
}
}q[maxn];
void LazyUpd(int nod)
{
lftree[nod * 2] = lftree[nod * 2 + 1] = lftree[nod];
ftree[nod * 2] = max(ftree[nod * 2], lftree[nod * 2]);
ftree[nod * 2 + 1] = max(ftree[nod * 2 + 1], lftree[nod * 2 + 1]);
lftree[nod] = 0;
}
void Init(int nod, int l, int r)
{
if (l == r)
{
ftree[nod] = f[l];
return;
}
int mid = (l + r) / 2;
Init(nod * 2, l, mid);
Init(nod * 2 + 1, mid + 1, r);
ftree[nod] = max(ftree[nod * 2], ftree[nod * 2 + 1]);
}
void Upd(int nod, int l, int r, int u, int v, int w)
{
if (l > v || r < u) return;
if (l >= u && r <= v)
{
ftree[nod] = w;
lftree[nod] = w;
return;
}
if (lftree[nod]) LazyUpd(nod);
int mid = (l + r) / 2;
Upd(nod * 2, l, mid, u, v, w);
Upd(nod * 2 + 1, mid + 1, r, u, v, w);
ftree[nod] = max(ftree[nod * 2], ftree[nod * 2 + 1]);
}
int Max(int nod, int l, int r, int u, int v)
{
if (l > v || r < u) return 0;
if (l >= u && r <= v) return ftree[nod];
if (lftree[nod]) LazyUpd(nod);
int mid = (l + r) / 2;
int L = Max(nod * 2, l, mid, u, v);
int R = Max(nod * 2 + 1, mid + 1, r, u, v);
return max(L, R);
}
///Shortcuts
void Upd(int u, int v, int w) {Upd(1, 1, n, u, v, w);}
int Max(int u, int v) {return Max(1, 1, n, u, v);}
namespace Sub1
{
void Main()
{
int res = 1;
int d = 2;
a[n + 1] = 1e9 + 69;
for (int i = 2; i <= n; i ++)
{
if (a[i + 1] - a[i] == a[i] - a[i - 1]) d ++;
else res = max(res, d), d = 2;
}
bool f2 = 0;
for (int i = 1; i <= Q; i ++)
{
if (q[i].req == 2) f2 = 1;
else if (q[i].req == 3)
{
if (f2 == 0) cout << res << "\n";
else cout << n << "\n";
}
}
}
}
namespace Sub2
{
void Main()
{
for (int t = 1; t <= Q; t ++)
{
int L = q[t].L;
int R = q[t].R;
int S = q[t].S;
int C = q[t].C;
if (q[t].req == 1)
{
for (int i = L; i <= R; i ++)
a[i] = a[i] + S + 1ll * (i - L) * C;
}
else if (q[t].req == 2)
{
for (int i = L; i <= R; i ++)
a[i] = S + 1ll * (i - L) * C;
}
else
{
int res = 1, cur = 2;
long long d = a[L + 1] - a[L];
for (int i = L + 1; i < R; i ++)
{
if (a[i + 1] - a[i] == d) cur ++;
else
{
res = max(res, cur);
cur = 2;
d = a[i + 1] - a[i];
}
}
res = max(res, cur);
if (L == R) res = 1;
cout << res << "\n";
}
}
}
}
namespace Sub3
{
void Main()
{
g[1] = 1;
g[2] = 2;
for (int i = 2; i < n; i ++)
{
if (a[i + 1] - a[i] == a[i] - a[i - 1]) g[i + 1] = g[i] + 1;
else g[i + 1] = 2;
}
f[n] = 1;
f[n - 1] = 2;
for (int i = n - 1; i > 1; i --)
{
if (a[i - 1] - a[i] == a[i] - a[i + 1]) f[i - 1] = f[i] + 1;
else f[i - 1] = 2;
}
Init(1, 1, n);
for (int t = 1; t <= Q; t ++)
{
int L = q[t].L;
int R = q[t].R;
int res = min(R - L + 1, max(f[L], g[R]));
int l = L + f[L];
int r = R - g[R];
if (l <= r) res = max(res, Max(l, r));
if (l - 1 != r + 1)
{
res = max(res, f[l - 1]);
res = max(res, g[r + 1]);
}
res = min(res, R - L + 1);
cout << res << "\n";
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cerr << "Processing...\n\n";
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
// freopen(TASK".OUT", "w", stdout);
}
cin >> n >> Q;
for (int i = 1; i <= n; i ++) cin >> a[i];
bool all_1_n = 1;
bool no_change = 1;
for (int i = 1; i <= Q; i ++)
{
q[i].inp();
if (q[i].L != 1 || q[i].R != n) all_1_n = 0;
if (q[i].req != 3) no_change = 0;
}
if (n <= 1000 && Q <= 1000) Sub2::Main();
else if (all_1_n) Sub1::Main();
else if (no_change) Sub3::Main();
// Sub3::Main();
cerr << "\n\n-----------------\n";
return 0;
}
Compilation message
Progression.cpp: In function 'int main()':
Progression.cpp:201:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
201 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
13776 KB |
Output is correct |
2 |
Correct |
116 ms |
9388 KB |
Output is correct |
3 |
Correct |
113 ms |
9404 KB |
Output is correct |
4 |
Correct |
114 ms |
9332 KB |
Output is correct |
5 |
Correct |
116 ms |
9376 KB |
Output is correct |
6 |
Correct |
113 ms |
9412 KB |
Output is correct |
7 |
Correct |
114 ms |
9408 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
169 ms |
13968 KB |
Output is correct |
12 |
Correct |
171 ms |
13900 KB |
Output is correct |
13 |
Correct |
175 ms |
14248 KB |
Output is correct |
14 |
Correct |
197 ms |
14140 KB |
Output is correct |
15 |
Correct |
169 ms |
14104 KB |
Output is correct |
16 |
Correct |
174 ms |
13876 KB |
Output is correct |
17 |
Correct |
176 ms |
13892 KB |
Output is correct |
18 |
Correct |
173 ms |
13888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
244 ms |
20564 KB |
Output is correct |
2 |
Correct |
107 ms |
8900 KB |
Output is correct |
3 |
Correct |
98 ms |
8876 KB |
Output is correct |
4 |
Correct |
101 ms |
8844 KB |
Output is correct |
5 |
Correct |
98 ms |
9032 KB |
Output is correct |
6 |
Correct |
101 ms |
9064 KB |
Output is correct |
7 |
Correct |
106 ms |
9012 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
326 ms |
20704 KB |
Output is correct |
12 |
Correct |
252 ms |
22112 KB |
Output is correct |
13 |
Correct |
287 ms |
20608 KB |
Output is correct |
14 |
Correct |
272 ms |
20756 KB |
Output is correct |
15 |
Correct |
216 ms |
21972 KB |
Output is correct |
16 |
Correct |
195 ms |
22648 KB |
Output is correct |
17 |
Correct |
211 ms |
22556 KB |
Output is correct |
18 |
Correct |
162 ms |
22596 KB |
Output is correct |
19 |
Correct |
252 ms |
21996 KB |
Output is correct |
20 |
Correct |
267 ms |
21972 KB |
Output is correct |
21 |
Correct |
241 ms |
21980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
181 ms |
12820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
244 ms |
20564 KB |
Output is correct |
2 |
Correct |
107 ms |
8900 KB |
Output is correct |
3 |
Correct |
98 ms |
8876 KB |
Output is correct |
4 |
Correct |
101 ms |
8844 KB |
Output is correct |
5 |
Correct |
98 ms |
9032 KB |
Output is correct |
6 |
Correct |
101 ms |
9064 KB |
Output is correct |
7 |
Correct |
106 ms |
9012 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
326 ms |
20704 KB |
Output is correct |
12 |
Correct |
252 ms |
22112 KB |
Output is correct |
13 |
Correct |
287 ms |
20608 KB |
Output is correct |
14 |
Correct |
272 ms |
20756 KB |
Output is correct |
15 |
Correct |
216 ms |
21972 KB |
Output is correct |
16 |
Correct |
195 ms |
22648 KB |
Output is correct |
17 |
Correct |
211 ms |
22556 KB |
Output is correct |
18 |
Correct |
162 ms |
22596 KB |
Output is correct |
19 |
Correct |
252 ms |
21996 KB |
Output is correct |
20 |
Correct |
267 ms |
21972 KB |
Output is correct |
21 |
Correct |
241 ms |
21980 KB |
Output is correct |
22 |
Incorrect |
159 ms |
17348 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
13776 KB |
Output is correct |
2 |
Correct |
116 ms |
9388 KB |
Output is correct |
3 |
Correct |
113 ms |
9404 KB |
Output is correct |
4 |
Correct |
114 ms |
9332 KB |
Output is correct |
5 |
Correct |
116 ms |
9376 KB |
Output is correct |
6 |
Correct |
113 ms |
9412 KB |
Output is correct |
7 |
Correct |
114 ms |
9408 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
169 ms |
13968 KB |
Output is correct |
12 |
Correct |
171 ms |
13900 KB |
Output is correct |
13 |
Correct |
175 ms |
14248 KB |
Output is correct |
14 |
Correct |
197 ms |
14140 KB |
Output is correct |
15 |
Correct |
169 ms |
14104 KB |
Output is correct |
16 |
Correct |
174 ms |
13876 KB |
Output is correct |
17 |
Correct |
176 ms |
13892 KB |
Output is correct |
18 |
Correct |
173 ms |
13888 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
2 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
2 ms |
332 KB |
Output is correct |
40 |
Correct |
244 ms |
20564 KB |
Output is correct |
41 |
Correct |
107 ms |
8900 KB |
Output is correct |
42 |
Correct |
98 ms |
8876 KB |
Output is correct |
43 |
Correct |
101 ms |
8844 KB |
Output is correct |
44 |
Correct |
98 ms |
9032 KB |
Output is correct |
45 |
Correct |
101 ms |
9064 KB |
Output is correct |
46 |
Correct |
106 ms |
9012 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
328 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
326 ms |
20704 KB |
Output is correct |
51 |
Correct |
252 ms |
22112 KB |
Output is correct |
52 |
Correct |
287 ms |
20608 KB |
Output is correct |
53 |
Correct |
272 ms |
20756 KB |
Output is correct |
54 |
Correct |
216 ms |
21972 KB |
Output is correct |
55 |
Correct |
195 ms |
22648 KB |
Output is correct |
56 |
Correct |
211 ms |
22556 KB |
Output is correct |
57 |
Correct |
162 ms |
22596 KB |
Output is correct |
58 |
Correct |
252 ms |
21996 KB |
Output is correct |
59 |
Correct |
267 ms |
21972 KB |
Output is correct |
60 |
Correct |
241 ms |
21980 KB |
Output is correct |
61 |
Incorrect |
181 ms |
12820 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |