QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578569#9313. Make MaxsazhiWA 23ms4368kbC++201.8kb2024-09-20 20:04:242024-09-20 20:04:25

Judging History

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

  • [2024-09-20 20:04:25]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:4368kb
  • [2024-09-20 20:04:24]
  • 提交

answer

// author:  jieda
// file:	cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (ll i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long  ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const ll N = 1e6+1e5+1e4,M = 1e5+10,INF = 0x3f3f3f3f,mod = 1e9+7;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-3;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;

void solve(){	
    int mx = 0;
	int n;cin>>n;
	vector<int> a(n+2);
	fa(i,1,n) cin>>a[i],mx = max(mx,a[i]);
	deque<int> q;
	ll ans = 0;

	a[0] = a[n+1] =  INF;
	q.push_back(0);
	for(int i = 1;i<=n;i++){
	    if(a[i]<=a[q.back()]){
	        q.push_back(i);
	        continue;
	    }
		while(q.size()>1&&a[q.back()]<a[i]){
			q.pop_back();
		}
		ans += i-q.back()-1;
	//	cout<<i-q.back()-1<<'\n';
		q.push_back(i);
	}
//	cout<<ans<<'\n';
	q = deque<int>();
	q.push_back(n+1);
	for(int i = n;i>=1;i--){
	    if(a[i]<a[q.back()]){
            q.push_back(i);
	        continue;
	    }
		while(q.size()>1&&a[q.back()]<a[i]){
			q.pop_back();
		}
		if(a[i] != mx){
		    ans += q.back()-i-1;
		    q.push_back(i);
		}
		//cout<<ans<<'\n';
	}
	cout<<ans<<'\n';
}	

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
/**/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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: 23ms
memory: 4368kb

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:

5907843
5215233

result:

wrong answer 1st numbers differ - expected: '4084978', found: '5907843'