QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#594237 | #9313. Make Max | sbj_noier | WA | 122ms | 22800kb | C++14 | 1.2kb | 2024-09-27 20:31:42 | 2024-09-27 20:31:44 |
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];
bool vis[maxn];
inline void ipt(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
b[i]=a[i];
vis[i]=false;
}
vis[n+1]=false;
vis[0]=false;
}
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];
vis[u]=true;
if(vis[u-1]){
int v=find(u-1);
if(c[v]==c[u]){
fa[v]=u;
sz[u]+=sz[v];
}
else {
fa[v]=u;
ans+=sz[v];
sz[u]+=sz[v];
}
}
if(vis[u+1]){
int v=find(u+1);
fa[v]=u;
ans+=sz[v];
sz[u]+=sz[v];
}
}
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: 14544kb
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: 122ms
memory: 22800kb
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:
3515786 3939627
result:
wrong answer 1st numbers differ - expected: '4084978', found: '3515786'