QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569057#9313. Make MaxfasctideWA 0ms3808kbC++14941b2024-09-16 20:15:182024-09-16 20:15:19

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 20:15:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-09-16 20:15:18]
  • 提交

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;
} 

Details

Tip: Click on the bar to expand more detailed information

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'