# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981966 | 2024-05-13T17:23:18 Z | vjudge1 | Sequence (APIO23_sequence) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int sequence(int n, vector <long long> a){ vector <vector <long long>> repe(n+1, vector<long long>(n+1)); for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ repe[i][j] = repe[i][j-1] + (a[j-1] == i); } } long long ans = 0; for(int i=0; i<n; i++){ ordered_set st; for(int j=i; j<n; j++){ st.insert(a[j]); int x = st.order_of_key(j/2); int y = st.order_of_key((j+1)/2); ans = max(ans, repe[x][j+1]-repe[x][i]); } st.clear(); } return ans; }