Submission #959406

#TimeUsernameProblemLanguageResultExecution timeMemory
959406PringBigger segments (IZhO19_segments)C++17
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3","unroll-loops") #pragma GCC target("avx2","popcnt","sse4","abm") #include <bits/stdc++.h> using namespace std; #ifdef MIKU string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m"; #define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x) void dout() { cout << dbrs << endl; } template <typename T, typename ...U> void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); } #else #define debug(...) 39 #endif // #define int long long #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) using ll = long long; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int MXN = 500005; int n, a[MXN]; int dp[MXN]; ll pre[MXN]; vector<pli> dq; int ptr; inline int R(){ int ans = 0; char c = readchar(); bool minus = false; while((c < '0' or c > '9') and c != '-' and c != EOF) c = readchar(); if(c == '-') minus = true, c = readchar(); while(c >= '0' and c <= '9') ans = ans * 10 + (c ^ '0'), c = readchar(); return minus ? -ans : ans; } void DP(int id) { while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++; int l = dq[ptr - 1].sc; dp[id] = dp[l] + 1; pli now = mp(2 * pre[id] - pre[l], id); debug(now.fs, now.sc); while (dq.size() && dq.back().fs >= now.fs) dq.pop_back(); dq.push_back(now); } void miku() { // cin >> n; n = R(); FOR(i, 1, n + 1) a[i] = R(); FOR(i, 1, n + 1) pre[i] = pre[i - 1] + a[i]; dq.push_back(mp(0LL, 0)); FOR(i, 1, n + 1) DP(i); cout << dp[n] << '\n'; } int32_t main() { cin.tie(0) -> sync_with_stdio(false); cin.exceptions(cin.failbit); miku(); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int R()':
segments.cpp:33:24: error: 'readchar' was not declared in this scope
   33 |  int ans = 0; char c = readchar(); bool minus = false;
      |                        ^~~~~~~~
segments.cpp: In function 'void DP(int)':
segments.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
      |            ~~~~^~~~~~~~~~~
segments.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 39
      |                    ^~
segments.cpp:44:5: note: in expansion of macro 'debug'
   44 |     debug(now.fs, now.sc);
      |     ^~~~~