家人们,谁懂啊,豆包改了好几次代码,结果都没AC,尽快看看吧,6.28考试了!

#include<bits/stdc++.h>
using namespace std;
const int MAXN=100000;
const int MAXA=1000000;

long long suf[MAXA+10];
bool hasL[MAXA+10];
int l[MAXN];
int lcnt;
int markY[MAXA+10];
int cnt_round;

long long calc(int a[],int n){
    for(int i=0;i<=MAXA;i++) suf[i]=0;
    for(int i=0;i<=MAXA;i++) hasL[i]=0;
    for(int i=0;i<=MAXA;i++) markY[i]=0;
    lcnt=0;
    long long res=0;
    cnt_round=0;

    for(int i=0;i<n;i++) suf[a[i]]++;

    for(int j=0;j<n;j++){
        int y=a[j];
        suf[y]--;
        if(suf[y]>0){
            cnt_round++;
            for(int i=0;i<lcnt;i++){
                int x=l[i];
                if(x == y) continue;
                if(markY[x] != cnt_round){
                    res++;
                    markY[x] = cnt_round;
                }
            }
        }
        if(!hasL[y]){
            hasL[y]=true;
            l[lcnt++]=y;
        }
    }
    return res;
}

int main(){
    int a[MAXN];
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<calc(a,n)<<endl;
    return 0;
}

0 条评论

目前还没有评论...

信息

ID
3001
难度
9
分类
(无)
标签
递交数
78
已通过
2
通过率
3%
上传者