QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#594116 | #9313. Make Max | sbj_noier | WA | 171ms | 25680kb | C++14 | 2.2kb | 2024-09-27 19:21:25 | 2024-09-27 19:21:26 |
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],pre[maxn],nxt[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;
fa[0]=0,fa[n+1]=0;
pre[0]=0;
nxt[0]=1;
pre[n+1]=n;
nxt[n+1]=n+1;
for(int i=1;i<=n;i++)pre[i]=i-1,nxt[i]=i+1;
for(int i=1;i<=m;i++){
for(int j=0;j<e[i].size();j++){
int u=e[i][j];
u=find(u);
int v1=pre[u],v2=nxt[u];
v1=find(v1);
v2=find(v2);
if(c[v1]==c[v2]){
if(c[u]<c[v1]){
fa[u]=v1;
nxt[v1]=v2;
ans+=sz[u];
sz[v1]+=sz[u];
}
else if(c[u]==c[v1]){
fa[u]=v1;
nxt[v1]=v2;
sz[v1]+=sz[u];
}
}
else if(c[v1]>c[v2]){
if(c[u]<c[v2]){
fa[u]=v2;
pre[v2]=v1;
ans+=sz[u];
sz[v2]+=sz[u];
}
else if(c[u]==c[v2]){
fa[u]=v2;
pre[v2]=v1;
sz[v2]+=sz[u];
}
else if(c[u]<c[v1]){
fa[u]=v1;
nxt[v1]=v2;
ans+=sz[u];
sz[v1]+=sz[u];
}
else if(c[u]==c[v1]){
fa[u]=v1;
nxt[v1]=v2;
sz[v1]+=sz[u];
}
}
else {
if(c[u]<c[v1]){
fa[u]=v1;
nxt[v1]=v2;
ans+=sz[u];
sz[v1]+=sz[u];
}
else if(c[u]==c[v1]){
fa[u]=v1;
nxt[v1]=v2;
sz[v1]+=sz[u];
}
else if(c[u]<c[v2]){
fa[u]=v2;
pre[v2]=v1;
ans+=sz[u];
sz[v2]+=sz[u];
}
else if(c[u]==c[v2]){
fa[u]=v2;
pre[v2]=v1;
sz[v2]+=sz[u];
}
}
// 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18616kb
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: 171ms
memory: 25680kb
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:
3713798 4130372
result:
wrong answer 1st numbers differ - expected: '4084978', found: '3713798'