/**
* \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;
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];
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";
}
}
}
}
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();
// Sub1::Main();
cerr << "\n\n-----------------\n";
return 0;
}
Compilation message
Progression.cpp: In function 'int main()':
Progression.cpp:113:10: warning: variable 'no_change' set but not used [-Wunused-but-set-variable]
113 | bool no_change = 1;
| ^~~~~~~~~
Progression.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
9156 KB |
Output is correct |
2 |
Correct |
112 ms |
6424 KB |
Output is correct |
3 |
Correct |
110 ms |
6468 KB |
Output is correct |
4 |
Correct |
118 ms |
6468 KB |
Output is correct |
5 |
Correct |
110 ms |
6608 KB |
Output is correct |
6 |
Correct |
114 ms |
6492 KB |
Output is correct |
7 |
Correct |
110 ms |
6468 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 |
162 ms |
9168 KB |
Output is correct |
12 |
Correct |
196 ms |
9028 KB |
Output is correct |
13 |
Correct |
163 ms |
9404 KB |
Output is correct |
14 |
Correct |
164 ms |
9400 KB |
Output is correct |
15 |
Correct |
199 ms |
9320 KB |
Output is correct |
16 |
Correct |
162 ms |
9092 KB |
Output is correct |
17 |
Correct |
160 ms |
9012 KB |
Output is correct |
18 |
Correct |
198 ms |
9028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
472 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
372 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 |
368 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
8432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
175 ms |
8492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
8432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
9156 KB |
Output is correct |
2 |
Correct |
112 ms |
6424 KB |
Output is correct |
3 |
Correct |
110 ms |
6468 KB |
Output is correct |
4 |
Correct |
118 ms |
6468 KB |
Output is correct |
5 |
Correct |
110 ms |
6608 KB |
Output is correct |
6 |
Correct |
114 ms |
6492 KB |
Output is correct |
7 |
Correct |
110 ms |
6468 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 |
162 ms |
9168 KB |
Output is correct |
12 |
Correct |
196 ms |
9028 KB |
Output is correct |
13 |
Correct |
163 ms |
9404 KB |
Output is correct |
14 |
Correct |
164 ms |
9400 KB |
Output is correct |
15 |
Correct |
199 ms |
9320 KB |
Output is correct |
16 |
Correct |
162 ms |
9092 KB |
Output is correct |
17 |
Correct |
160 ms |
9012 KB |
Output is correct |
18 |
Correct |
198 ms |
9028 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
472 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
372 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 |
368 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Incorrect |
115 ms |
8432 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |