Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
36069 | 武云帆 | 【S】T2 | C++ | 解答错误 | 75 | 1906 MS | 476 KB | 1242 | 2025-02-07 15:10:39 |
#include<bits/stdc++.h> using namespace std; const int N=10010; int n; long long a[N]; long long ans=0; int main(){ ios::sync_with_stdio(false); cin.tie(0); //freopen("book.in","r",stdin); //freopen("book.out","w",stdout); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){ priority_queue<int> q1; priority_queue<int,vector<int>,greater<int> >q2; q2.push(a[i]); ans+=a[i]*i*i*1ll; //cout<<i<<" "<<i<<" "<<a[i]<<" "<<ans<<endl; for(int j=i+1;j<=n;j++) { if(q2.top()<a[j]) q2.push(a[j]); else q1.push(a[j]); if((j-i)%2==0){ while(q1.size()+1>q2.size()){ q2.push(q1.top()); q1.pop(); } while(q1.size()+1<q2.size()){ //cout<<q2.size()<<" "<<q2.top()<<endl; q1.push(q2.top()); q2.pop(); } ans+=i*j*q2.top()*1ll; //cout<<q1.top()<<" "<<q2.size()<<" "<<i<<" "<<j<<" "<<q2.top()<<" "<<ans<<endl; } //ans+=i*j*q2.top(); } } cout<<ans; return 0; }