#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include "sequence.h"
using namespace std;
const int LIM = 5e5+1;
vector<long long> bit(LIM,0);
int n;
void add(int p,int v) {
for (int i=p;i<=n;i+=i&-i) bit[i]+=v;
}
long long get(int p) {
long long ans = 0;
for (int i=p;i>0;i-=i&-i) ans+=bit[i];
return ans;
}
int sequence(int N, std::vector<int> A) {
n = N;
vector<int> sme(N+1);
vector<int> sm(N+1);
for (int i=1;i<=N;i++) {
add(A[i-1],1);
sme[i] = get(A[i-1]);
sm[i] = get(A[i-1]-1);
}
vector<int> poss[N+1];
for (int i=1;i<=n;i++) poss[A[i-1]].push_back(i);
int l = 1;
int r = N;
while (l<=r) {
int m = (l+r) >> 1;
bool flag = 0;
for (int i=1;i<=n;i++) {
int sz = poss[i].size();
for (int j=0;j+m-1<sz;j++) {
int smme = sme[poss[i][j+m-1]]-sme[poss[i][j]]+1;
int smm = sm[poss[i][j+m-1]]-sm[poss[i][j]];
int len = (poss[i][j+m-1]-poss[i][j]+1);
int mid = (len+1)/2;
if (smme >= mid && smm < mid) flag = 1;
if (len%2==0 && smm<mid+1 && smme>=mid+1) flag = 1;
}
}
if (flag) l = m+1;
else r = m-1;
}
return r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4184 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4184 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
95 ms |
33684 KB |
Output is correct |
3 |
Incorrect |
100 ms |
33620 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
78 ms |
26944 KB |
Output is correct |
3 |
Correct |
80 ms |
25920 KB |
Output is correct |
4 |
Correct |
80 ms |
26052 KB |
Output is correct |
5 |
Correct |
82 ms |
26904 KB |
Output is correct |
6 |
Correct |
91 ms |
26044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
39564 KB |
Output is correct |
2 |
Correct |
146 ms |
39560 KB |
Output is correct |
3 |
Incorrect |
161 ms |
38988 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4184 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4184 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |