Submission #1094901

#TimeUsernameProblemLanguageResultExecution timeMemory
1094901raphaelpBouquet (EGOI24_bouquet)C++14
0 / 100
37 ms3524 KiB
#include <bits/stdc++.h> using namespace std; class SegTree { private: vector<int> st; int N; int l(int x) { return (x << 1); } int r(int x) { return (x << 1) + 1; } void update(int L, int R, int a, int val, int x) { if (L > a || R < a) return; if (L == a && R == a) { st[x] = val; } else { int m = (L + R) / 2; update(L, m, a, val, l(x)); update(m + 1, R, a, val, r(x)); st[x] = max(st[l(x)], st[r(x)]); } } int RMQ(int L, int R, int a, int b, int x) { if (L > b || R < a) return 0; if (L >= a && R <= b) return st[x]; int m = (L + R) / 2; return max(RMQ(L, m, a, b, l(x)), RMQ(m + 1, R, a, b, r(x))); } public: SegTree(int x) { N = pow(2, ceil(log2(N))); st.assign(2 * N, 0); } void update(int x, int val) { update(0, N - 1, x, val, 1); } int RMQ(int a, int b) { if (a > b) return 0; else return RMQ(0, N - 1, a, b, 1); } }; int main() { int N; cin >> N; vector<int> lef(N), rig(N); for (int i = 0; i < N; i++) { cin >> lef[i] >> rig[i]; } SegTree ST(N); vector<int> dp(N); priority_queue<pair<int, int>> PQ; int ans = 0; for (int i = 0; i < N; i++) { while (!PQ.empty() && -PQ.top().first < i) { ST.update(PQ.top().second, dp[PQ.top().second]); PQ.pop(); } dp[i] = ST.RMQ(0, i - lef[i] - 1); dp[i]++; PQ.push({-(i + rig[i]), i}); ans = max(ans, dp[i]); } cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:39:16: warning: 'ST.SegTree::N' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |         N = pow(2, ceil(log2(N)));
      |             ~~~^~~~~~~~~~~~~~~~~~
#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...