QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569057 | #9313. Make Max | fasctide | WA | 0ms | 3808kb | C++14 | 941b | 2024-09-16 20:15:18 | 2024-09-16 20:15:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
void solve() {
int n;
cin>>n;
vector<int>a(n+2);
vector<int>l(n+1),r(n+1);
for (int i=1;i<=n;i++) cin>>a[i];
a[0]=0;
a[n+1]=0;
stack<int>s1;
s1.push(0);
for (int i=1;i<=n;i++) {
while (!s1.empty()&&a[i]>a[s1.top()]) s1.pop();
if (!s1.empty()) l[i]=s1.top()+1;
else {
l[i]=1;
}
s1.push(i);
}
stack<int>s2;
s2.push(n+1);
for (int i=n;i>=1;i--) {
while (!s2.empty()&&a[i]>a[s2.top()]) s2.pop();
if (!s2.empty()) r[i]=s2.top()-1;
else {
r[i]=n;
}
s2.push(i);
}
ll ans=0;
for (int i=1;i<=n;i++) {
cout<<l[i]<<" "<<r[i]<<'\n';
ans+=r[i]-l[i];
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
// T=1;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3808kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 1 1 2 1 1 1 2 2 0 1 1 2 2 3 3 1 4 5 5 6 6 7 7 3 1 1 1 2 1 3 3
result:
wrong answer 2nd numbers differ - expected: '0', found: '1'