제출 #627268

#제출 시각아이디문제언어결과실행 시간메모리
627268ngpin04Bigger segments (IZhO19_segments)C++17
100 / 100
455 ms253068 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define getbit(x, i) (x >> i) & 1 #define TASK "" #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int N = 5e5 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); pair <int, int> dp[N]; pair <int, int> val[50 * N]; long long s[N]; int ptr[50 * N][2]; int a[N]; int n,cnt; void add(long long x, pair <int, int> v) { int cur = 0; for (int i = 49; i >= 0; i--) { int &p = ptr[cur][getbit(x, i)]; if (!p) p = ++cnt; cur = p; maxi(val[cur], v); } } pair <int, int> getmax(long long x) { int cur = 0; pair <int, int> res = mp(0, 0); for (int i = 49; i >= 0; i--) { int d = getbit(x, i); if (d == 1) maxi(res, val[ptr[cur][d ^ 1]]); cur = ptr[cur][d]; if (cur == 0) break; } maxi(res, val[cur]); return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ONLINE_JUDGE // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); #endif cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; s[i] = s[i - 1] + a[i]; } add(0, mp(0, 0)); for (int i = 1; i <= n; i++) { long long tot = 0; pair <int, int> pir = getmax(s[i]); pir.fi++; dp[i] = pir; int j = pir.se; // cerr << i << " " << j << "\n"; add(s[i] - s[j] + s[i], mp(dp[i].fi, i)); } cout << dp[n].fi; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'int main()':
segments.cpp:71:13: warning: unused variable 'tot' [-Wunused-variable]
   71 |   long long tot = 0;
      |             ^~~
#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...