QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576031 | #9313. Make Max | vvvvt | WA | 33ms | 5188kb | C++14 | 870b | 2024-09-19 18:01:51 | 2024-09-19 18:01:52 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int n,m,a[N];
stack<int> stk;
void vvvvt(){
int n;cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
stack<int> s1;
stack<pair<int,int>> s2;
int cnt1=0,cnt2=0,ans1=0,ans2=0;
for(int i=1;i<=n;i++){
int flag=0;
while(s1.size()&&s1.top()<a[i]) s1.pop(),cnt1++,flag=1;
if(flag==1)ans1+=cnt1;
else cnt1=0;
s1.push(a[i]);
}
reverse(a+1,a+1+n);
for(int i=1;i<=n;i++){
int flag=0;
while(s2.size()&&s2.top().first<a[i]) s2.pop(),cnt2++,flag=1;
if(flag==1)ans2+=cnt2;
else cnt2=0;
if(s2.size()&&s2.top().first==a[i]){
ans2-=i-s2.top().second-1;
}
s2.push({a[i],i});
}
cout<<ans1+ans2<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _=1;
cin>>_;
while(_--) vvvvt();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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: 33ms
memory: 5188kb
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:
521791 501680
result:
wrong answer 1st numbers differ - expected: '4084978', found: '521791'