QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575673 | #9313. Make Max | WulongQAQ | WA | 0ms | 7716kb | C++14 | 1.3kb | 2024-09-19 16:12:44 | 2024-09-19 16:12:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// typedef long long ll;
#define endl '\n'
#define int long long
#define lowbit(x) ((x) & (-x))
const int N = 1e6 + 7, M = 207, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int l[N], r[N], st[N], a[N];
void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int id = 0;
for (int i = 1; i <= n; i++)
{
while (id && a[i] > a[st[id]])
id--;
l[i] = st[id] + 1;
st[++id] = i;
}
id = 0;
st[id] = n + 1;
for (int i = n; i >= 1; i--)
{
while (id && a[i] > a[st[id]])
id--;
r[i] = st[id] - 1;
if (a[i] == a[st[id]])
r[i] = i;
st[++id] = i;
}
// for (int i = 1; i <= n; i++)
// cout << l[i] << " ";
// cout << endl;
// for (int i = 1; i <= n; i++)
// cout << r[i] << " ";
// cout << endl;
int ans = 0;
for (int i = 1; i <= n; i++)
ans = ans + (r[i] - l[i]);
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
// cout << fixed << setprecision(10) << c << endl;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7716kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 -3 -3 -21
result:
wrong answer 2nd numbers differ - expected: '0', found: '-3'