QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#712786#8050. Random Permutationacwing_gza#WA 624ms9852kbC++201.4kb2024-11-05 17:02:112024-11-05 17:02:12

Judging History

This is the latest submission verdict.

  • [2024-11-05 17:02:12]
  • Judged
  • Verdict: WA
  • Time: 624ms
  • Memory: 9852kb
  • [2024-11-05 17:02:11]
  • Submitted

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: 1ms
memory: 7936kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 624ms
memory: 9852kb

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:

249612204181694

result:

wrong answer 1st numbers differ - expected: '250202478701074', found: '249612204181694'