- 糖葫芦(haw)
- @ 2026-06-27 20:23:10
家人们,谁懂啊,豆包改了好几次代码,结果都没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;
}
2 条评论
-
202607gj16张子瑞 (张子瑞) LV 9 @ 2026-07-21 18:49:39
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e6+10; int a[MAXN]; unordered_map<int,vector<int>>val_pos; unordered_set<string>unique_pair; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; val_pos[a[i]].push_back(i); } for(auto&[y,pos_list]:val_pos) { int m=pos_list.size(); if(m<2)continue; int first_j=pos_list[0]; int first_k=pos_list[1]; unordered_set<int>temp_x; for(int i=0;i<first_j;i++) { int x=a[i]; if(x==y)continue; temp_x.insert(x); } for(int x:temp_x) { string key=to_string(x)+"_"+to_string(y); if(unique_pair.find(key)==unique_pair.end()) { unique_pair.insert(key); } } } cout<<unique_pair.size()<<endl; return 0; } `80pts`` -
@ 2026-07-12 12:16:36
豆包只能的80pts
- 1
信息
- ID
- 3001
- 难度
- 9
- 分类
- (无)
- 标签
- 递交数
- 78
- 已通过
- 2
- 通过率
- 3%
- 上传者