# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
690874 | drdilyor | Bigger segments (IZhO19_segments) | C++17 | 1 ms | 328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
const string fileio = "";
constexpr int tests = 0, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;
int solve() {
int n; cin >> n;
vector<int> arr(n);
for (auto& i : arr) {cin >> i;}
vector<ll> pref(n+1);
for (int i = 0; i < n; i++)
pref[i+1] = pref[i] + arr[i];
vector<ll> dp(n+1), cnt(n+1);
pair a = {-1, -1}, b{0, -1};
for (int i = 0; i < n ;i++) {
ll s = 0;
auto check = [&](int j)->bool {
if (pref[i+1] - pref[j] >= dp[j]) {
return true;
}
return false;
};
auto search = [&](int lb, int rb) {
bool found = 1;
lb--; rb++;
while (lb < rb-1) {
int m = (lb+rb) / 2;
if (check(m)) {found = 1; lb = m;}
else rb =m;
}
if (found) {
dp[i+1] = pref[i+1] - pref[lb];
cnt[i+1] = cnt[lb]+1;
}
};
dp[i+1] = pref[i+1];
cnt[i+1] = 1;
int x = cnt[i];
auto [l, r] = equal_range(cnt.begin(), cnt.begin()+i+1, cnt[i]);
assert(r == cnt.begin()+i+1);
auto [l1, r1] = equal_range(cnt.begin(), cnt.begin()+i+1, cnt[i]-1);
assert(r1 == l);
search(l1-cnt.begin(), r1-cnt.begin());
search(l-cnt.begin(), r-cnt.begin());
}
debug(dp);
debug(cnt);
cout << cnt.back() << '\n';
return 0;
}
signed main() {
int t = 1;
#ifdef ONPC
t = 10000;
#else
if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
#endif
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit | cin.eofbit);
cout << fixed << setprecision(8);
if (tests) cin >> t;
while (t-- && cin) {
if (solve()) break;
#ifdef ONPC
cout << "____________________" << endl;
#endif
}
return 0;
}
/*
█████ █████ ███ ████
▒▒███ ▒▒███ ▒▒▒ ▒▒███
███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████
███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███
▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒
▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███
▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████
▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒
███ ▒███
▒▒██████
▒▒▒▒▒▒
*/
Compilation message (stderr)
# | 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... |