ee这样写不应该是O(n)的吗,为啥有几个点跑1.4s+
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,t;
ll a[214514],b[214514];
ll cnt,res,op;
ll st[214514],f,sum;
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>t;
while(t--)
{
cnt=0;
res=0;
memset(st,0,sizeof st);
sum=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
for(int i=1;i<=n;i++)
{
if(st[a[i]]==1)
res=max(res,a[i]);
else
st[a[i]]=1;
//sum+=a[i];
a[i]=res;
}
memset(st,0,sizeof st);
res=0;
for(int i=1;i<=n;i++)
{
sum+=a[i];
if(st[a[i]]==1)
res=max(res,a[i]);
else
st[a[i]]=1;
a[i]=res;
cnt+=a[i];
}
//for(int i=1;i<=n;i++)
//cout<<99999<<endl;
for(int i=n;cnt>0;i--)
{
sum+=cnt;
cnt-=a[i];
}
cout<<sum<<'\n';
}
return 0;
}