Submission #791392

#TimeUsernameProblemLanguageResultExecution timeMemory
791392tkm_algorithmsSequence (APIO23_sequence)C++17
7 / 100
90 ms34784 KiB
#include "sequence.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; template<class T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #define sz(a) (int)a.size() #define fi first #define se second #define pb push_back vector<pair<int,int>> v[500000]; Tree<pair<int,int>> S; map<int,int> tot; int n; int sequence(int N, vector<int> a) { n = N; int ans = 1; for(int i = 0; i < n; i++){ int j = i; while(i<n-1 and a[i]==a[i+1]) i++; v[a[i]].pb({j,i-j+1}); ans = max(ans, i-j+1); } for(int i = 1; i <= n; i++){ if(sz(v[i])<2)continue; int y = v[i][0].se+v[i][1].se; int z = v[i][1].fi-(v[i][0].fi+v[i][0].se); int x = v[i][0].fi + n-1-(v[i][1].fi+v[i][1].se-1); if(x>=z-y) ans = max(ans, y); } return ans; }
#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...