QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578801#9313. Make MaxsazhiWA 47ms4260kbC++201.6kb2024-09-20 21:27:092024-09-20 21:27:11

Judging History

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

  • [2024-09-20 21:27:11]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:4260kb
  • [2024-09-20 21:27:09]
  • 提交

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] =  1e9;
	q.push_back(0);
	for(int i = 1;i<=n;i++){
		while(q.size()>1&&a[q.back()]<a[i]){
			q.pop_back();
		}
		int x = a[q.back()];
		auto pos = lower_bound(a.begin()+i+1,a.begin()+2+n,a[i]);
		int y = *pos;
    	if(x==a[i]&&y!=a[i]){
    	    ans += pos-a.begin()-i-1+i-q.back()-1;
    	}else if(y==a[i]&&x!=a[i]){
    	    ans += i-q.back()-1;
    	}else if(x!=a[i]&&y!=a[i]){
    	    ans += pos-a.begin()-i-1+i-q.back()-1;
    	}
		q.push_back(i);
	}

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

详细

Test #1:

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

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: 47ms
memory: 4260kb

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:

9787216369
9101104044

result:

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