QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#594083 | #9313. Make Max | sbj_noier | WA | 121ms | 22408kb | C++14 | 1.4kb | 2024-09-27 19:00:09 | 2024-09-27 19:00:10 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+10;
int t,n,m;
int a[maxn],b[maxn],c[maxn],fa[maxn],sz[maxn];
vector<int>e[maxn];
inline void ipt(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
b[i]=a[i];
}
}
inline void init(){
sort(b+1,b+n+1);
m=unique(b+1,b+n+1)-b-1;
for(int i=1;i<=n;i++){
c[i]=lower_bound(b+1,b+n+1,a[i])-b;
e[c[i]].push_back(i);
// printf("%lld ",c[i]);
}
// printf("\n");
}
inline int find(int x){
if(fa[x]==x)return x;
return fa[x]=find(fa[x]);
}
inline void solve(){
int ans=0;
for(int i=1;i<=n;i++)fa[i]=i,sz[i]=1;
for(int i=1;i<=m;i++){
for(int j=0;j<e[i].size();j++){
int u=e[i][j];
int v1=u-1,v2=u+1;
u=find(u);
v1=find(v1);
v2=find(v2);
if(c[v1]<c[v2])swap(v1,v2);
if(c[u]<c[v2]){
fa[u]=v2;
ans+=sz[u];
sz[v2]+=sz[u];
sz[u]=0;
}
else if(c[u]<c[v1]){
fa[u]=v1;
ans+=sz[u];
sz[v1]+=sz[u];
sz[u]=0;
}
else if(c[u]==c[v2]){
fa[u]=v2;
sz[v2]+=sz[u];
sz[u]=0;
}
else if(c[u]==c[v1]){
fa[u]=v1;
sz[v1]+=sz[u];
sz[u]=0;
}
// for(int k=1;k<=n;k++)printf("%lld ",fa[k]);
// printf("\n");
}
e[i].clear();
}
printf("%lld\n",ans);
}
signed main(){
scanf("%lld",&t);
while(t--){
ipt();
init();
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 15920kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3
result:
ok 4 number(s): "1 0 3 3"
Test #2:
score: -100
Wrong Answer
time: 121ms
memory: 22408kb
input:
2 198018 875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...
output:
240090 229904
result:
wrong answer 1st numbers differ - expected: '4084978', found: '240090'