이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
int N, Q;
vi L;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
L.resize(N);
for (int i = 0; i < N; ++i)
cin >> L[i];
cin >> Q;
while (Q--)
{
ll x, y, a, b;
cin >> x >> y >> a >> b;
--x;
L[x] = y;
vi B(L.begin() + a, L.begin() + b);
// starting with lower piece
vi dp(sz(B), -INF); // dp[i] := number of zigzag pieces in prefix i with i as minimum
dp[0] = 1;
for (int i = 1; i < sz(B); ++i)
{
ll buffer = 0;
int lowerbound = max(0, i - (int)ceil(log2(B[i])) - 1);
for (int j = i - 1; j >= lowerbound; --j)
{
buffer += B[j];
if (buffer > B[i])
{
dp[i] = max(dp[i], 2LL);
if (j > 0 && buffer > B[j - 1])
dp[i] = max(dp[i], dp[j - 1] + 2);
}
}
}
ll ans = max(1LL, dp.back());
ll buffer = 0;
for (int i = sz(B) - 1; i > 0; --i)
{
buffer += B[i];
if (buffer > B[i - 1])
ans = max(ans, dp[i - 1] + 1);
}
cout << ans << "\n";
}
}
# | 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... |