QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574449#9313. Make Maxhjx666RE 1ms3876kbC++174.5kb2024-09-18 22:09:162024-09-18 22:09:16

Judging History

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

  • [2024-09-18 22:09:16]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3876kb
  • [2024-09-18 22:09:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inv(x) ksm(x, mod - 2)
#define int long long
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define lowbit(x) ((x) & (-x))
#define mem(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int ksm(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pair<int, int>, int> piii;
const int N = 2e5 + 5;
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
int n, m, k;
int a[N];
int b[N];
int c[N];
int d[N];
int jc[N];
int jcinv[N];
void solve()
{
	cin>>n;
	vector<int> h(n + 1);
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n;i++)
		cin >> h[i];
	stack<pii> s,ss;
	for (int i = 1; i <= n;i++) 
	{
		if(!s.size())
		{
			s.push({h[i], 1});
			a[i] = 0;
			continue;
		}
		while(s.size()&&h[i]>s.top().first)
			a[i] += s.top().second, s.pop();
		s.push({h[i], a[i]+1});
	}

	for (int i = n; i >= 1;i--)
	{
		if(!ss.size())
		{
			ss.push({h[i], 1});
			b[i] = 0;
			continue;
		}
		while(ss.size()&&ss.top().first<h[i])
			b[i] += ss.top().second, ss.pop();
		if(h[i]==ss.top().first)
			b[i] = 0;
		ss.push({h[i], b[i] + 1});
	}
	int sum = 0;
	map<int, int> f;
	for (int i = 1; i <= n;i++)
	{
		//if(!f[h[i]])
			sum += a[i] + b[i], f[h[i]] = 1;
	}
		
	cout << sum << endl;
}
signed main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int t;
	t = 1;
	cin >> t;
	while (t--)
		solve();
}
/*
 * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3876kb

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
Runtime Error

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:


result: