Submission #497463

#TimeUsernameProblemLanguageResultExecution timeMemory
497463NalrimetBigger segments (IZhO19_segments)C++17
0 / 100
8 ms12044 KiB
#include <bits/stdc++.h> #pragma GCC optimization("g", on) #pragma GCC optimize ("inline") #pragma GCC optimization("03") #pragma GCC optimization("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #define ll long long #define pb push_back #define F first #define S second using namespace std; const int N = 5 * 1e5 + 5; const int inf = 1e9 + 7; long long a[N], pref[N], dp[N], mn[N], lef[N]; vector<int> v[N]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; //8 //7 2 3 5 1 4 6 10 // pref[i] - pref[j] >= pref[j] - pref[k] // pref[i] >= 2 * pref[j] - pref[k] for(ll i = 1; i <= n; ++i){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for(ll i = 1; i <= n; ++i){ lef[i] = max(lef[i], lef[i - 1]); dp[i] = dp[lef[i]] + 1; int l, r, mid; l = i + 1; r = n; while(l < r){ mid = (l + r) / 2; if(2 * pref[i] - pref[lef[i]] <= pref[mid]) r = mid; else l = mid + 1; } lef[l] = max(lef[l], i); } cout << dp[n]; return 0; }

Compilation message (stderr)

segments.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("g", on)
      | 
segments.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization("03")
      | 
segments.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization("unroll-loops")
      | 
segments.cpp:7: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    7 | #pragma comment(linker, "/stack:200000000")
      |
#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...