이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int O = 5e3 + 5;
const int N = 5e5 + 5;
int n, a[N], sum[N], lim[O], Max[O], f[O][O], tree[O][O * 4];
vector <int> val[O];
void Update(int id, int l, int r, int u, int x, int t){
if (l > u || r < u) return ;
if (l == r){
tree[t][id] = x;
return;
}
int mid = (l + r) / 2;
Update(id << 1, l, mid, u, x, t);
Update(id << 1 | 1, mid + 1, r, u, x, t);
tree[t][id] = max(tree[t][id << 1], tree[t][id << 1 | 1]);
}
int Get(int id, int l, int r, int u, int v, int t){
if (l > v || r < u) return 0;
if (u <= l && r <= v) return tree[t][id];
int mid = (l + r) / 2;
return max(Get(id << 1, l, mid, u, v, t), Get(id << 1 | 1, mid + 1, r, u, v, t));
}
void sub2(){
for (int i = 1; i <= n; ++ i){
int x = 0;
for (int j = i; j >= 1; -- j){
x += a[j];
val[i].push_back(x);
}
sort(val[i].begin(), val[i].end());
lim[i] = val[i].size();
}
lim[0] = 1;
val[0].push_back(0);
for (int i = 1; i <= n; ++ i){
int x = 0;
for (int j = i; j >= 1; -- j){
x += a[j];
int id = lower_bound(val[j - 1].begin(), val[j - 1].end(), x) - val[j - 1].begin();
f[i][j] = max(f[i][j], Get(1, 0, lim[j - 1], id, lim[j - 1],j - 1) + 1);
id = lower_bound(val[i].begin(), val[i].end(), x) - val[i].begin();
Update(1, 0, lim[i], id, f[i][j], i);
}
}
cout << Get(1, 0, lim[n], 0, lim[n], n);
}
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
cin >> n;
for (int i = 1; i <= n; ++ i) cin >> a[i], sum[i] = sum[i - 1] + a[i];
if (n <= 5e3 + 5){
sub2();
return 0;
}
cout << rand() % n + 1;
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
61 | main(){
| ^~~~
# | 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... |