QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#270533#5543. The Only Modeyuto1115#TL 261ms35348kbC++232.8kb2023-12-01 00:10:092023-12-01 00:10:10

Judging History

你现在查看的是最新测评结果

  • [2023-12-01 00:10:10]
  • 评测
  • 测评结果:TL
  • 用时:261ms
  • 内存:35348kb
  • [2023-12-01 00:10:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010;
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);
  }
  void get(int v,int l,int r,int pos,int x,int &ans,int ind){
    if (!t[v].empty() && t[v].back().first>x){
      pair<int,int>fnd={x,N};
      auto it=upper_bound(t[v].begin(),t[v].end(),fnd);
      ans=max(ans,ind-it->second);
    }
    if (l==r) return;
    int m=(l+r)/2;
    if (pos<=m){
      get(v+v,l,m,pos,x,ans,ind);
    } else {
      get(v+v+1,m+1,r,pos,x,ans,ind);
    }
  }
  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> > >U(n*2+2);
      vector<vector<pair<pair<int,int>,int> > >G(n*2+2);
      for (int i=1;i<=n;i++){
        if (i==n || a[i+1]==other) 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});
        U[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<n*2+2;it++){
        if (G[it].empty() || U[it].empty()) continue;
        int j=0;
        for (auto cur:G[it]){
         // if (el==0 && other==2) cout<<"g = "<<it<<" "<<cur.first.first<<" "<<cur.first.second<<" "<<cur.second<<endl;
          while (j<U[it].size() && cur.second-U[it][j].second>ans){
            T.upd(1,1,n*2,1,U[it][j].first.first+n-1,U[it][j].first.second,U[it][j].second);
            j++;
          }
          T.get(1,1,n*2,cur.first.first+n,cur.first.second,ans,cur.second);
           // if (el==0 && other==2) cout<<"ind "<<el<<" "<<other<<" "<<ind<<" "<<cur.second<<endl;

        }
        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: 4ms
memory: 22236kb

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: 4ms
memory: 22256kb

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: 0ms
memory: 22240kb

input:

2
0 2

output:

1 0 1 0 

result:

ok single line: '1 0 1 0 '

Test #4:

score: 0
Accepted
time: 4ms
memory: 22204kb

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: 0
Accepted
time: 3ms
memory: 22176kb

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: 0
Accepted
time: 7ms
memory: 22944kb

input:

4207
3 1 0 3 2 0 3 1 1 1 1 3 0 1 1 0 2 2 3 0 1 1 0 1 0 2 0 1 0 0 3 3 1 0 1 3 3 0 2 0 2 0 1 0 2 3 2 3 0 0 0 0 1 2 1 2 0 2 2 0 3 3 2 2 0 2 2 0 3 0 1 3 1 1 0 2 3 0 1 2 1 2 0 0 1 1 0 3 3 2 0 2 1 3 0 1 0 3 0 0 0 2 2 2 0 1 1 0 3 1 1 3 3 2 2 1 3 3 1 3 2 0 2 3 2 2 1 0 2 3 0 1 0 0 1 1 1 3 3 1 3 3 3 0 0 0 3 2...

output:

2330 1520 4207 1359 

result:

ok single line: '2330 1520 4207 1359 '

Test #7:

score: 0
Accepted
time: 139ms
memory: 35348kb

input:

89925
0 0 0 3 0 3 0 2 3 2 3 1 0 0 0 2 2 1 3 3 0 0 1 0 0 3 0 1 0 0 1 1 0 0 1 2 1 3 1 2 1 2 2 1 0 2 2 3 0 0 1 0 2 3 2 3 0 0 1 0 0 1 2 1 3 0 0 0 2 1 1 0 1 3 2 2 0 0 2 3 2 3 3 1 3 3 0 2 0 2 2 0 2 1 3 0 1 1 0 0 1 0 3 1 2 2 2 0 2 0 2 3 2 0 0 2 3 3 1 0 1 2 2 2 1 2 0 0 3 2 3 0 1 1 3 3 0 0 0 3 0 2 0 0 2 3 1 ...

output:

89925 49888 75725 38162 

result:

ok single line: '89925 49888 75725 38162 '

Test #8:

score: 0
Accepted
time: 57ms
memory: 30932kb

input:

64937
1 1 0 2 1 1 3 1 1 1 2 0 3 1 1 2 1 2 2 1 0 2 1 1 1 1 1 0 3 1 0 2 1 0 0 0 0 2 1 2 1 2 2 1 2 3 2 1 2 1 3 0 1 3 0 0 1 3 1 2 2 2 0 3 3 1 3 0 3 3 2 0 1 1 2 0 3 3 3 2 1 0 1 0 1 3 0 0 2 1 0 3 3 1 2 3 2 1 1 0 0 3 1 1 2 1 0 2 1 0 0 1 1 3 0 1 2 1 3 2 0 3 1 2 1 2 0 0 0 1 1 2 3 3 2 1 1 1 2 1 3 1 2 2 2 0 1 ...

output:

64937 61901 51387 63870 

result:

ok single line: '64937 61901 51387 63870 '

Test #9:

score: 0
Accepted
time: 230ms
memory: 33324kb

input:

73423
1 2 2 0 0 0 0 2 1 2 1 2 1 3 1 3 3 0 1 2 2 0 0 0 3 2 1 1 0 3 0 2 1 3 1 1 2 3 0 1 2 1 0 0 0 3 3 0 3 2 3 3 1 1 3 2 0 0 0 3 2 0 0 2 3 3 3 3 3 2 3 2 2 2 3 3 0 1 1 2 2 2 1 2 2 1 1 2 1 2 2 3 0 3 0 2 2 2 1 2 1 1 2 3 0 1 3 2 0 3 3 3 0 2 2 2 3 1 0 1 0 1 1 3 0 0 2 1 1 3 1 3 3 2 0 2 2 1 1 0 1 0 2 3 1 2 3 ...

output:

36577 18616 60210 73423 

result:

ok single line: '36577 18616 60210 73423 '

Test #10:

score: 0
Accepted
time: 200ms
memory: 35116kb

input:

82517
2 1 1 0 2 0 3 1 3 1 3 3 2 2 3 0 3 2 2 0 2 1 0 2 2 3 2 0 1 0 1 2 2 1 1 1 3 2 2 0 1 0 0 3 3 1 1 0 3 1 3 1 2 3 3 3 3 3 2 1 3 1 3 0 2 0 2 0 2 2 2 2 2 1 2 1 3 3 2 3 2 3 0 2 0 1 0 0 3 2 1 1 0 1 2 1 1 0 1 3 1 3 3 2 2 3 0 2 1 3 2 1 0 1 2 3 2 2 3 3 1 0 2 0 3 2 3 0 1 2 0 3 3 0 2 1 1 3 3 2 2 0 2 2 1 1 2 ...

output:

50863 68187 40176 82517 

result:

ok single line: '50863 68187 40176 82517 '

Test #11:

score: 0
Accepted
time: 261ms
memory: 34512kb

input:

79392
0 2 2 2 0 3 2 3 1 1 1 0 0 3 1 3 3 0 2 2 0 0 0 2 1 0 2 2 2 1 2 3 2 0 3 3 3 2 0 1 0 1 1 1 0 1 0 1 0 2 3 3 0 1 2 3 0 1 0 1 0 1 2 2 1 3 0 0 1 3 1 2 2 1 0 0 2 1 0 0 2 2 3 1 3 0 3 2 0 0 0 0 3 3 0 0 2 2 0 2 0 2 3 1 0 2 2 1 2 2 0 3 3 3 2 1 3 1 1 1 1 2 0 0 1 1 1 0 1 1 1 3 3 0 2 3 1 1 0 1 2 3 1 3 3 0 0 ...

output:

68113 34911 26794 79392 

result:

ok single line: '68113 34911 26794 79392 '

Test #12:

score: -100
Time Limit Exceeded

input:

100000
2 0 0 1 0 2 3 3 0 2 1 2 0 2 0 3 0 0 2 0 1 1 0 1 1 1 1 0 2 2 0 1 0 1 0 0 0 3 1 0 3 0 1 1 1 3 1 0 1 3 1 1 1 0 1 3 0 1 1 0 1 3 0 0 0 0 0 0 0 1 0 0 1 3 1 3 0 1 0 0 2 1 1 2 2 0 3 3 2 1 1 0 0 1 1 2 0 1 2 0 3 3 1 1 1 0 3 3 0 1 3 0 1 0 2 1 3 3 2 3 2 0 2 3 0 2 2 2 0 1 0 0 1 0 2 1 1 1 2 1 2 1 1 0 3 1 1...

output:


result: