QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568571 | #9313. Make Max | Qing | WA | 1ms | 3876kb | C++20 | 1.6kb | 2024-09-16 17:08:32 | 2024-09-16 17:08:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define lowbit(x) ((x) & (-x))
#define ULL unsigned long long
const int N = 2e5 + 10;
const int P = 1e9 + 7;
const int mod1 = 1331;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
typedef pair<ll, ll> PII;
typedef tuple<ll, ll, ll> TII;
typedef vector<ll> vi;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
ll n, a[N];
/*
*/
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
stack<ll> st;
vector<ll> vis(n + 5, 0);
vector<ll> ans1(n + 5, 0), ans2(n + 5, 0);
for (int i = 1; i <= n; i++)
{
while (st.size() && a[st.top()] < a[i])
{
ans1[i] += ans1[st.top()] + 1;
st.pop();
}
st.push(i);
if (st.size() && a[st.top()] == a[i])
{
vis[st.top()] = 1;
}
st.push(i);
}
while (st.size())
{
st.pop();
}
for (int i = n; i >= 1; i--)
{
while (st.size() && a[st.top()] < a[i])
{
ans2[i] += ans2[st.top()] + 1;
st.pop();
}
st.push(i);
}
// for (int i = 1; i <= n; i++)
// {
// cout << ans1[i] << ' ';
// }
// cout << endl;
// for (int i = 1; i <= n; i++)
// {
// cout << ans2[i] << ' ';
// }
// cout << endl;
ll ans = 0;
for (int i = 1; i <= n; i++)
{
ans += ans1[i];
if (!vis[i])
{
ans += ans2[i];
}
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _ = 1;
cin >> _;
while (_--)
solve();
}
详细
Test #1:
score: 0
Wrong Answer
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:
2 0 6 8
result:
wrong answer 1st numbers differ - expected: '1', found: '2'