#include <bits/stdc++.h>
typedef long long ll;
class SparseTable {
public:
ll maxPow;
std::vector<ll> orig;
std::vector<std::vector<ll>> table_min, table_max;
SparseTable(const std::vector<ll> &x) {
orig = x;
const ll n = x.size();
maxPow = std::floor(std::log2(n));
table_min = std::vector<std::vector<ll>>(maxPow + 1, std::vector<ll>(n));
table_max = std::vector<std::vector<ll>>(maxPow + 1, std::vector<ll>(n));
for (ll i = 0; i < n; ++i) {
table_min[0][i] = x[i];
table_max[0][i] = x[i];
}
for (ll power = 1; power <= maxPow; ++power) {
for (ll i = 0; i < n - (1 << (power - 1)); ++i) {
table_min[power][i] =
std::min(table_min[power - 1][i],
table_min[power - 1][i + (1 << (power - 1))]);
table_max[power][i] =
std::max(table_max[power - 1][i],
table_max[power - 1][i + (1 << (power - 1))]);
}
}
}
ll query_min(ll a, ll b) {
if (a == b) {
return orig[a];
}
ll powToUse = std::ceil(std::log2(b - a + 1)) - 1;
return std::min(table_min[powToUse][a],
table_min[powToUse][b - (1 << powToUse) + 1]);
}
ll query_max(ll a, ll b) {
if (a == b) {
return orig[a];
}
ll powToUse = std::ceil(std::log2(b - a + 1)) - 1;
return std::max(table_max[powToUse][a],
table_max[powToUse][b - (1 << powToUse) + 1]);
}
};
ll BinarySearchMax(ll s, ll e, const std::function<bool(ll)> &f) {
ll ans = s;
while (s <= e) {
ll m = s + (e - s) / 2;
if (f(m)) {
ans = m;
s = m + 1;
} else {
e = m - 1;
}
}
return ans;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, q;
std::cin >> n >> q;
std::vector<ll> d(n);
for (auto &i : d) {
std::cin >> i;
}
while (q--) {
ll t;
std::cin >> t;
ll l, r;
std::cin >> l >> r;
--l, --r;
if (t == 1) {
ll s, c;
std::cin >> s >> c;
for (ll i = l; i <= r; ++i) {
d[i] += s + (i - l) * c;
}
} else if (t == 2) {
ll s, c;
std::cin >> s >> c;
for (ll i = l; i <= r; ++i) {
d[i] = s + (i - l) * c;
}
} else {
std::vector<ll> diff(n);
std::adjacent_difference(d.begin(), d.end(), diff.begin());
SparseTable table(diff);
ll ans = 1;
if (l == r) {
std::cout << ans << '\n';
continue;
}
for (ll i = l; i <= r; ++i) {
ans =
std::max(ans, BinarySearchMax(i + 1, r,
[&](ll m) {
return table.query_min(i + 1, m) ==
table.query_max(i + 1, m);
}) -
i + 1);
}
std::cout << ans << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3029 ms |
101704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
672 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
25 ms |
604 KB |
Output is correct |
9 |
Correct |
28 ms |
604 KB |
Output is correct |
10 |
Correct |
30 ms |
856 KB |
Output is correct |
11 |
Correct |
50 ms |
604 KB |
Output is correct |
12 |
Correct |
28 ms |
604 KB |
Output is correct |
13 |
Correct |
50 ms |
636 KB |
Output is correct |
14 |
Correct |
49 ms |
604 KB |
Output is correct |
15 |
Correct |
29 ms |
604 KB |
Output is correct |
16 |
Correct |
25 ms |
604 KB |
Output is correct |
17 |
Correct |
25 ms |
604 KB |
Output is correct |
18 |
Correct |
28 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3075 ms |
101660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3028 ms |
101608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3075 ms |
101660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3029 ms |
101704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |