QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568571#9313. Make MaxQingWA 1ms3876kbC++201.6kb2024-09-16 17:08:322024-09-16 17:08:32

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 17:08:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3876kb
  • [2024-09-16 17:08:32]
  • 提交

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'