QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568824 | #9313. Make Max | security | WA | 29ms | 4084kb | C++14 | 1.8kb | 2024-09-16 18:43:32 | 2024-09-16 18:43:32 |
Judging History
answer
#include<cstdio>
#include<utility>
#include<stack>
using namespace std;
using ll = long long;
/*
const int N = 2e5+10;
ll a[N];
inline ll cm(int n){
ll sum = 0;
for(int i=1;i<=n;i++)
sum+=i;
// cout<<"***"<<sum<<endl;
return sum;
}
void solve(){
stack<int>s;
multiset<int>ss;
ll maxx = -1;
ll ans = 0;
int n; cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i],maxx = max(a[i],maxx),ss.insert(a[i]);
for(int i=1;i<=n;i++){
if(s.empty() || s.top() == a[i]) s.push(a[i]);
else if(a[i] == maxx&&ss.count(maxx)==1){
ans = ans+n-1;
while(s.size()) s.pop();
// cout<<ans<<endl;
}else if(a[i]>s.top()){
ans += s.size();
s.push(a[i]);
// cout<<ans<<endl;
}else if(a[i] == s.top()){
ans += 1;
// cout<<ans<<endl;
}else{
int j = i;
s.push(a[j]);
while(a[j]>=a[j+1]&&j<=n){
j++;
}
ans = ans+cm(j-i+1);
i = j;
// cout<<ans<<endl;
}
}
cout<<ans<<endl;}*/
using PII = pair<int,ll>;
stack<PII> sps;
inline ll op(int t){
ll c1=0;
ll c2=0;
int prev=sps.top().first;
while(sps.size() && prev<t){
if(sps.top().first>prev){
c2+=c1;
}
c1+=sps.top().second;
//printf("%d:",c1);
prev=sps.top().first;
sps.pop();
}
if(sps.size() && sps.top().first==t)sps.top().second+=c1+1;
else sps.push({t,c1+1});
//printf("\n");
return c1+c2;
}
void solve(){
int n,i,t;
scanf("%d",&n);
scanf("%d",&t);
sps.push({t,1});
ll ans=0,lt=0;
for(i=1;i<n;i++){
scanf("%d",&t);
if(t>sps.top().first){
ans+=op(t);
}else if(t==sps.top().first){
sps.top().second+=1;
}else{
sps.push({t,1});
}
}
while(sps.size()>1){
lt+=sps.top().second;
ans+=lt;
//printf("%d:",lt);
sps.pop();
}
printf("%lld\n",ans);
sps.pop();
}
int main(){
int T;
scanf("%d",&T);
while(T--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3
result:
ok 4 number(s): "1 0 3 3"
Test #2:
score: -100
Wrong Answer
time: 29ms
memory: 4084kb
input:
2 198018 875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...
output:
8485441931 7871046413
result:
wrong answer 1st numbers differ - expected: '4084978', found: '8485441931'