QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576341 | #9313. Make Max | lp | WA | 198ms | 17848kb | C++14 | 2.6kb | 2024-09-19 19:59:50 | 2024-09-19 19:59:50 |
Judging History
answer
#include<algorithm>//sort
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<utility>//pair
#include<map>
#include<stack>
#include<vector>
//#define int long long
using namespace std;
//void so()
//{
// int n,s;
// long long sum = 0;
// stack<int>q;
// map<int, int>ma;
// cin >> n;
// for (int i = 1; i <= n; i++)
// {
// cin >> s;
// ma[s] = 1;
// while (q.size() && q.top()<s)
// {
// ma[s] += ma[q.top()];
// sum += ma[q.top()];
// q.pop();
// }
// q.push(s);
// }
// int a[200005];
// n = q.size();
// while (q.size())
// {
// a[q.size()] = q.top();
// q.pop();
// }
// int ss = 0;
// for (int i = n; i >= 2; i--)
// {
// if (a[i] != a[i - 1])
// {
// sum += a[i];
// }
// ss += a[i];
// }
// cout << sum << endl;
//}
void so()
{
int n;
cin >> n;
vector<int>a(n),b(n);
vector<vector<int>> vec(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
b[i] = a[i];
}
//离散化,只需要知道大小
sort(b.begin(), b.end());//排序
unique(b.begin(), b.end());//去重
for (int i = 0; i < n; ++i)
{
a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
vec[a[i]].push_back(i);//!!!
}
vector<int> lst(n);
vector<int> rst(n);
stack<int>sta;
for (int i = 0; i < n; i++)
{
while (sta.size() && a[sta.top()] <= a[i])
{
sta.pop();
}
lst[i] = sta.size()?sta.top():-1;
sta.push(i);//下标入栈
}
while (sta.size()) sta.pop();
for (int i = n-1; i >=0; i--)
{
while (sta.size() && a[sta.top()] <=a[i])
{
sta.pop();
}
rst[i] = sta.size() ? sta.top() : -1;
sta.push(i);
}
vector<int>c(n);
long long anss = 0;
for (int i = 0; i < n; i++)
{
for (auto j: vec[i])
{
int fa;
if (rst[j] == -1 && lst[j] == -1) continue;
if (lst[j] == -1)
{
fa = rst[j];
}
else if(rst[j]==-1)
{
fa = lst[j];
}
else if (lst[j] > rst[j])
{
fa = rst[j];
}
else
{
fa = lst[j];
}
c[fa] = c[fa]+c[j] + 1;
anss += c[j] + 1;
}
}
cout << anss << '\n';
/*vector<int> ans(n);
for (int j = n - 1; j >= 0; --j) {
for (auto& i : vec[j]) {
int fa;
if (rst[i] == -1 && lst[i] == -1) continue;
if (rst[i] == -1) fa = lst[i];
else if (lst[i] == -1) fa = rst[i];
else if (a[rst[i]] > a[lst[i]]) fa = lst[i];
else fa = rst[i];
ans[i] = ans[fa] + 1;
}
}
long long anss = 0;
for (int i = 0; i < n; ++i) {
anss += ans[i];
}
cout << anss << '\n';*/
}
int main()
{
int t;
cin >> t;
while (t--)
{
so();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 198ms
memory: 17848kb
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:
2151880 2292908
result:
wrong answer 1st numbers differ - expected: '4084978', found: '2151880'