이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
// #define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int MXN = 500005;
int n, a[MXN];
int dp[MXN];
ll pre[MXN];
vector<pli> dq;
int ptr;
void DP(int id) {
while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
int l = dq[ptr - 1].sc;
dp[id] = dp[l] + 1;
pli now = mp(2 * pre[id] - pre[l], id);
debug(now.fs, now.sc);
while (dq.size() && dq.back().fs >= now.fs) dq.pop_back();
dq.push_back(now);
}
void miku() {
cin >> n;
FOR(i, 1, n + 1) cin >> a[i];
FOR(i, 1, n + 1) pre[i] = pre[i - 1] + a[i];
dq.push_back(mp(0LL, 0));
FOR(i, 1, n + 1) DP(i);
cout << dp[n] << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'void DP(int)':
segments.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
| ~~~~^~~~~~~~~~~
segments.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
segments.cpp:35:5: note: in expansion of macro 'debug'
35 | debug(now.fs, now.sc);
| ^~~~~
# | 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... |