QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#270522#5543. The Only Modeyuto1115#TL 1162ms37332kbC++232.7kb2023-11-30 23:39:092023-11-30 23:39:09

Judging History

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

  • [2023-11-30 23:39:09]
  • 评测
  • 测评结果:TL
  • 用时:1162ms
  • 内存:37332kb
  • [2023-11-30 23:39: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);
  }
  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+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});
        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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 22980kb

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: 22400kb

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: 24060kb

input:

2
0 2

output:

1 0 1 0 

result:

ok single line: '1 0 1 0 '

Test #4:

score: 0
Accepted
time: 3ms
memory: 23304kb

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

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: 0
Accepted
time: 20ms
memory: 24916kb

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: 1162ms
memory: 37332kb

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: 654ms
memory: 33556kb

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: 860ms
memory: 34168kb

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: 918ms
memory: 34932kb

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: 1112ms
memory: 35848kb

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: