Submission #983339

#TimeUsernameProblemLanguageResultExecution timeMemory
983339vjudge1Sequence (APIO23_sequence)C++17
28 / 100
2120 ms1289960 KiB
#include "sequence.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; pair<int, int> mids(int sz) { int m1 = sz / 2; int m2 = sz / 2 + (sz % 2); return {m1, m2}; } int sequence(int N, std::vector<int> A) { int res = 0; vector<map<int, int>> p(A.size() + 1); for (size_t i = 0; i < A.size(); ++i) { for (auto [key, val]: p[i]) { p[i + 1][key] = val; } p[i + 1][A[i]]++; } for (int l = 0; l < (int)A.size(); ++l) { tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> st; for (int r = l; r < (int)A.size(); ++r) { st.insert(pair{A[r], r}); auto [m1, m2] = mids(st.size() - 1); m1 = st.find_by_order(m1)->first; m2 = st.find_by_order(m2)->first; res = max(res, max(p[r + 1][m1] - p[l][m1], p[r + 1][m2] - p[l][m2])); } } return res; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...