제출 #562839

#제출 시각아이디문제언어결과실행 시간메모리
562839tamthegodBigger segments (IZhO19_segments)C++14
100 / 100
85 ms18924 KiB
#include<iostream> #include<iomanip> #include<algorithm> #include<stack> #include<queue> #include<string> #include<string.h> #include<cmath> #include<vector> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<cstdio> #include<bitset> #include<chrono> #include<random> #include<ext/rope> /* ordered_set #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e6 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, a[maxN]; ll sum[maxN]; ll f[maxN], pos[maxN]; void ReadInput() { cin >> n; for(int i=1; i<=n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } } void Solve() { fill(f + 1, f + n + 1, 1); for(int i=1; i<=n; i++) { if(f[i] < f[i - 1] || (f[i] == f[i - 1] && pos[i] < pos[i - 1])) { f[i] = f[i - 1]; pos[i] = pos[i - 1]; } int j = pos[i]; ll val = 2 * sum[i] - sum[j]; int id = lower_bound(sum + 1, sum + n + 1, val) - sum; if(f[id] < f[i] + 1 || (f[id] == f[i] + 1 && pos[id] < i)) { f[id] = f[i] + 1; pos[id] = i; } } cout << f[n]; } int32_t main() { // freopen("x.inp", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(nullptr); ReadInput(); Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...