QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#270517 | #5543. The Only Mode | yuto1115# | RE | 3ms | 14424kb | C++23 | 2.6kb | 2023-11-30 23:30:44 | 2023-11-30 23:30:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
int a[N];
struct SegTree{
vector<pair<int,int> >t[N*4];
vector<int>used;
void upd(int v,int l,int r,int L,int R,int y,int i){
if (l>R || r<L) return;
if (l>=L && r<=R){
if (t[v].empty() || t[v].back().first < y){
used.push_back(v);
t[v].push_back({y,i});
// cout<<"SEG "<<l<<" "<<r<<" "<<y<<" "<<i<<endl;
}
return;
}
int m=(l+r)/2;
upd(v+v,l,m,L,R,y,i);
upd(v+v+1,m+1,r,L,R,y,i);
}
int get(int v,int l,int r,int pos,int x){
int cur=N;
pair<int,int>fnd={x,N};
auto it=upper_bound(t[v].begin(),t[v].end(),fnd);
if (it!=t[v].end()) cur=it->second;
if (l==r) return cur;
int m=(l+r)/2;
if (pos<=m){
cur=min(cur,get(v+v,l,m,pos,x));
} else {
cur=min(cur,get(v+v+1,m+1,r,pos,x));
}
return cur;
}
void clear(){
for (int i:used){
t[i].clear();
}
}
};
SegTree T;
int cnt[N][4];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i];
for (int j=0;j<4;j++){
cnt[i][j]=cnt[i-1][j];
}
cnt[i][a[i]]++;
}
vector<int>res(4,0);
for (int el=0;el<4;el++){
int ans=0;
for (int i=1;i<=n;i++){
int mx=0;
for (int j=0;j<4;j++){
if (j==el) continue;
mx=max(mx,cnt[i][j]);
}
if (mx<cnt[i][el]) ans=i;
}
for (int other=0;other<4;other++){
if (other==el) continue;
vector<int>val;
for (int i=0;i<4;i++){
if (i==el || i==other) continue;
val.push_back(i);
}
vector<vector<pair<pair<int,int>,int> > >g(n*2+1);
for (int i=1;i<=n;i++){
g[cnt[i][el]-cnt[i][other]+n].push_back({{cnt[i][val[0]]-cnt[i][el],cnt[i][val[1]]-cnt[i][el]},i});
g[cnt[i][el]-cnt[i][other]+n+1].push_back({{cnt[i][val[0]]-cnt[i][el],cnt[i][val[1]]-cnt[i][el]},-i});
}
for (int it=0;it<g.size();it++){
if (g[it].empty()) continue;
for (auto cur:g[it]){
// if (el==0 && other==2) cout<<"g = "<<it<<" "<<cur.first.first<<" "<<cur.first.second<<" "<<cur.second<<endl;
if (cur.second < 0){
T.upd(1,1,n*2,1,cur.first.first+n-1,cur.first.second,-cur.second);
} else {
int ind = T.get(1,1,n*2,cur.first.first+n,cur.first.second);
// if (el==0 && other==2) cout<<"ind "<<el<<" "<<other<<" "<<ind<<" "<<cur.second<<endl;
ans=max(ans,cur.second-ind);
}
}
T.clear();
}
}
res[el]=ans;
}
for (int i=0;i<4;i++){
cout<<res[i]<<" ";
}
cout<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14080kb
input:
7 1 2 2 0 3 0 3
output:
4 1 5 3
result:
ok single line: '4 1 5 3 '
Test #2:
score: 0
Accepted
time: 2ms
memory: 13092kb
input:
12 2 0 1 0 2 1 1 0 2 3 3 3
output:
4 9 1 9
result:
ok single line: '4 9 1 9 '
Test #3:
score: 0
Accepted
time: 3ms
memory: 13012kb
input:
2 0 2
output:
1 0 1 0
result:
ok single line: '1 0 1 0 '
Test #4:
score: 0
Accepted
time: 2ms
memory: 14424kb
input:
12 3 0 2 2 1 0 2 1 3 3 2 3
output:
1 5 11 8
result:
ok single line: '1 5 11 8 '
Test #5:
score: -100
Runtime Error
input:
1 1
output:
0 1 0 0