QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#712778 | #8050. Random Permutation | acwing_gza# | WA | 626ms | 9752kb | C++20 | 1.4kb | 2024-11-05 17:01:03 | 2024-11-05 17:01:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int maxn=3e5+9;
int n,a[maxn],p[maxn];
int val[maxn];
ll cnt[maxn*2+9];
ll &get(int k) { return cnt[k+maxn]; }
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;++i) cin>>a[i],p[a[i]]=i,val[i]=1;
ll res=0;
for(int v=1;v<=n;++v)
{
int pos=p[v];
int MAXL;
int dis=abs(v-n/2);
if(dis<1) dis=1;
MAXL=1ll*n*n/(long long)(powl(dis,1.65));
// if(MAXL<30) MAXL=30;
if(MAXL>n) MAXL=n;
int l=pos-MAXL,r=pos+MAXL;
if(l<1) l=1;
if(r>n) r=n;
ll ans=0;
int sl=0,sr=0;
val[pos]=-1;
for(int i=pos;i>=l;--i)
{
sl+=val[i];
// printf("sl=%d\n",sl);
get(sl)++;
}
for(int j=pos;j<=r;++j)
{
sr+=val[j];
// printf("sr=%d\n",sr);
// sl+sr-2val[pos]=0/1
// sl=0/1+2val[pos](-2)-sr
ans+=get(-2-sr)+get(-1-sr);
}
res+=1ll*ans*v;
// printf("%d %lld\n",v,ans);
get(0)=0;
for(int s=-1;;--s)
{
if(!get(s)) break;
get(s)=0;
}
for(int s=1;;++s)
{
if(!get(s)) break;
get(s)=0;
}
}
cout<<res<<endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9732kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 626ms
memory: 9752kb
input:
100000 56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...
output:
249612182631912
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '249612182631912'