QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398976#8050. Random Permutationucup-team173TL 1233ms5016kbC++231.2kb2024-04-25 20:36:352024-04-25 20:36:37

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 20:36:37]
  • 评测
  • 测评结果:TL
  • 用时:1233ms
  • 内存:5016kb
  • [2024-04-25 20:36:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mpr make_pair
#define fi first
#define se second
#define db double
// #define int long long

char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p1=buf,p2=buf+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
void read(int&x){
    char c=GC;x=0;
    while(!isdigit(c))c=GC;
    while(isdigit(c))x=x*10+c-'0',c=GC;
}

const int maxn=3e5+10;
int n;
int p[maxn];
const int lim=1000;
int t[lim*2+10],pos[maxn];

void solve(){
    read(n);
    for(int i=1;i<=n;i++)read(p[i]),pos[p[i]]=i;
    ll ans=0;
    for(int w=1;w<=n;w++){
        int i=p[w];
        memset(t,0,sizeof t);
        int cur=lim;
        for(int r=w;r<=n;r++){
            cur+=(p[r]>p[w]?1:-1);
            if(cur<0||cur>lim*2)break;
            t[cur]++;
        }
        cur=1+lim;
        for(int l=w;l;l--){
            cur+=(p[l]>p[w]?1:-1);
            if(cur<2||cur>lim*2-2)break;
            ans+=(t[lim*2-cur]+t[lim*2-cur-1])*i;
        }
    }
    cout<<ans<<"\n";
    
}
signed main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3668kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: 0
Accepted
time: 1233ms
memory: 5016kb

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:

250202478701074

result:

ok 1 number(s): "250202478701074"

Test #3:

score: -100
Time Limit Exceeded

input:

200000
70900 189146 39056 135530 191967 133789 108558 81993 132081 113826 54456 127761 27836 64897 87159 105191 109446 81230 75525 90396 75756 50200 43091 151358 100791 193998 157161 119352 176873 120724 134471 155040 138534 182263 161855 4577 124893 199710 60764 146460 75314 43696 129155 64816 1390...

output:


result: