#include "sequence.h"
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,a[5000500],val[5000500],pref[5000500];
vector<int> pos[5000500];
int query_mn(int l,int r){
int mn=1e9;
for(int i=l;i<=r;i++) mn=min(mn,pref[i]);
return mn;
}
int query_mx(int l,int r){
int mx=-1e9;
for(int i=l;i<=r;i++) mx=max(mx,pref[i]);
return mx;
}
int min_diff(int l1,int r1,int l2,int r2){
if(max(l1,l2)<=min(r1,r2)) return 0;
return min(abs(l1-r2),abs(l2-r1));
}
bool good(int l,int r,int c){
return min_diff(query_mn(0,l),query_mx(0,l),query_mn(r,n),query_mx(r,n))<=c;
}
int sequence(int N,vector<int> A) {
n=N; for(int i=1;i<=n;i++) a[i]=A[i-1];
for(int i=1;i<=n;i++) pos[a[i]].pb(i);
//build(1,1,n);
for(int i=1;i<=n;i++) val[i]=1;
int ans=0;
for(int v=1;v<=n;v++){
if(pos[v].empty()) continue;
for(int j:pos[v]) val[j]--;
for(int i=1;i<=n;i++) pref[i]=pref[i-1]+val[i];
int sz=(int)pos[v].size();
int ptr=0;
for(int i=0;i<sz;i++){
while(ptr<sz&&good(pos[v][i],pos[v][ptr],ptr-i+1)) ptr++;
ans=max(ans,ptr-i);
}
for(int j:pos[v]) val[j]--;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
123476 KB |
Output is correct |
2 |
Correct |
25 ms |
123620 KB |
Output is correct |
3 |
Correct |
27 ms |
123740 KB |
Output is correct |
4 |
Correct |
25 ms |
123484 KB |
Output is correct |
5 |
Correct |
25 ms |
123740 KB |
Output is correct |
6 |
Incorrect |
25 ms |
123740 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
123476 KB |
Output is correct |
2 |
Correct |
25 ms |
123620 KB |
Output is correct |
3 |
Correct |
27 ms |
123740 KB |
Output is correct |
4 |
Correct |
25 ms |
123484 KB |
Output is correct |
5 |
Correct |
25 ms |
123740 KB |
Output is correct |
6 |
Incorrect |
25 ms |
123740 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
123476 KB |
Output is correct |
2 |
Execution timed out |
2045 ms |
143600 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
123620 KB |
Output is correct |
2 |
Execution timed out |
2027 ms |
135836 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2027 ms |
149228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
123476 KB |
Output is correct |
2 |
Correct |
25 ms |
123620 KB |
Output is correct |
3 |
Correct |
27 ms |
123740 KB |
Output is correct |
4 |
Correct |
25 ms |
123484 KB |
Output is correct |
5 |
Correct |
25 ms |
123740 KB |
Output is correct |
6 |
Incorrect |
25 ms |
123740 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
123476 KB |
Output is correct |
2 |
Correct |
25 ms |
123620 KB |
Output is correct |
3 |
Correct |
27 ms |
123740 KB |
Output is correct |
4 |
Correct |
25 ms |
123484 KB |
Output is correct |
5 |
Correct |
25 ms |
123740 KB |
Output is correct |
6 |
Incorrect |
25 ms |
123740 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |