제출 #998484

#제출 시각아이디문제언어결과실행 시간메모리
998484underwaterkillerwhaleBigger segments (IZhO19_segments)C++17
13 / 100
3 ms10752 KiB
#include <bits/stdc++.h> #define se second #define fs first #define mp make_pair #define pb push_back #define ll long long #define ii pair<ll,ll> #define ld long double #define SZ(v) (int)v.size() #define ALL(v) v.begin(), v.end() #define bit(msk, i) ((msk >> i) & 1) #define iter(id, v) for(auto id : v) #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define reb(i,m,n) for(int i=(m); i>=(n); i--) using namespace std; mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count()); ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); } const int N = 5e5 + 7; const int Mod = 998244353; const int szBL = 916; const ll INF = 1e18; const int BASE = 137; int n; ll a[N]; ll dp[N][2], pre[N]; struct fenwick_tree { int Range; ll fen[N]; void init (int n) { Range = n; rep (i, 1, n) fen[i] = -1; } void update (int pos, ll val) { for (; pos <= Range; pos += pos & -pos) fen[pos] = max(fen[pos], val); } ll get (int pos) { ll res = -1; for (; pos > 0; pos -= pos & -pos) res = max(res, fen[pos]); return res; } }BIT; void solution () { cin >> n; rep (i, 1, n) cin >> a[i]; rep (i, 1, n) pre[i] = pre[i - 1] + a[i]; memset(dp, 0x3f, sizeof dp); dp[0][0] = 0; int res = 0; rep (k, 1, 60) { rep (i, 0, n) dp[i][k & 1] = INF; static vector<ll> vec; vec.clear(); rep (i, 0, n) vec.push_back(dp[i][k&1^1] + pre[i]); sort (ALL(vec)); ll nval; vec.resize (nval = unique(ALL(vec)) - vec.begin()); BIT.init(nval); rep (i, 0, n) { int posprei = upper_bound(ALL(vec), pre[i]) - vec.begin(); if (BIT.get(posprei) != -1) { dp[i][k & 1] = pre[i] - BIT.get(posprei); } int pos = lower_bound(ALL(vec), dp[i][k&1^1] + pre[i]) - vec.begin() + 1; BIT.update (pos, pre[i]); } rep (i, 0, n) { if (dp[i][k & 1] < INF) res = k; } } cout << res <<"\n"; } #define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // file ("c"); int num_Test = 1; // cin >> num_Test; while (num_Test--) solution(); } /* 5 10 1 2 3 1 4 2 5 3 1 4 2 3 3 5 4 5 3 4 1 4 */

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

segments.cpp: In function 'void solution()':
segments.cpp:59:44: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   59 |         rep (i, 0, n) vec.push_back(dp[i][k&1^1] + pre[i]);
      |                                           ~^~
segments.cpp:69:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   69 |             int pos = lower_bound(ALL(vec), dp[i][k&1^1] + pre[i]) - vec.begin() + 1;
      |                                                   ~^~
#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...