#include "sequence.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = 2050;
int cnt[N];
int tree[N * 4 + 512];
void add(int node, int cl, int cr, int id){
tree[node] ++ ;
if(cl == cr){
return;
}
int mid = (cl + cr) / 2;
if(mid >= id)
add(node * 2, cl, mid, id);
else
add(node * 2 + 1, mid + 1, cr, id);
}
int find_idx(int node, int cl, int cr, int lim){
if(cl == cr) {
return tree[node];
}
int mid = (cl + cr) / 2;
if(tree[node * 2] >= lim){
return find_idx(node * 2, cl, mid, lim);
}
else{
return find_idx(node * 2 + 1, mid + 1, cr, lim - tree[node * 2]);
}
}
void init(int node, int cl, int cr){
tree[node] = 0;
if(cl == cr) return;
int mid = (cl + cr) / 2;
init(node * 2, cl, mid);
init(node * 2 + 1, mid + 1, cr);
}
int sequence(int n, vector<int> a) {
if(n > 2000){
int las = -1;
int cnt = 0;
int res = 0;
for(int i = 0 ; i < n; i ++ ){
if(a[i] == las){
cnt ++ ;
}
else{
cnt = 1;
las = a[i];
}
res = max(res, cnt);
}
return res;
}
int ans = 0;
int sz;
int me;
for(int i = 0 ; i < n; i ++) {
init(1, 1, n);
for(int j = i ; j < n; j ++) {
add(1, 1, n, a[j]);
sz = j - i + 1;
if(sz % 2 == 1){
me = (sz + 1) / 2;
ans = max(ans, find_idx(1, 1, n, me));
}
else{
me = (sz + 1) / 2;
ans = max(ans, find_idx(1, 1, n, me));
ans = max(ans, find_idx(1, 1, n, me + 1));
}
}
for(auto x : me) cnt[x] = 0;
}
return ans;
}
Compilation message
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:85:22: error: 'begin' was not declared in this scope
85 | for(auto x : me) cnt[x] = 0;
| ^~
sequence.cpp:85:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
from sequence.cpp:2:
/usr/include/c++/10/valarray:1224:5: note: 'std::begin'
1224 | begin(const valarray<_Tp>& __va)
| ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
from sequence.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:549:3: note: 'std::filesystem::__cxx11::begin'
549 | begin(recursive_directory_iterator __iter) noexcept
| ^~~~~
sequence.cpp:85:22: error: 'end' was not declared in this scope
85 | for(auto x : me) cnt[x] = 0;
| ^~
sequence.cpp:85:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
from sequence.cpp:2:
/usr/include/c++/10/valarray:1244:5: note: 'std::end'
1244 | end(const valarray<_Tp>& __va)
| ^~~
In file included from /usr/include/c++/10/filesystem:46,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
from sequence.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:554:3: note: 'std::filesystem::__cxx11::end'
554 | end(recursive_directory_iterator) noexcept
| ^~~