QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568050 | #9313. Make Max | TD0210 | WA | 219ms | 20348kb | C++23 | 1.8kb | 2024-09-16 15:04:19 | 2024-09-16 15:04:20 |
Judging History
answer
//子序列:不连续
//子串:连续
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX
using namespace std;
const int N = 2e5 + 1000;
const int mod = 1e9 + 7;
int dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 };
struct edge
{
};
ll dp[32];
void solve()
{
ll n;
cin >> n;
vector<ll> num(n + 1, 0), ans1(n + 1, 0), ans2(n + 1, 0);
for (int i = 1;i <= n;i++) {
cin >> num[i];
}
stack<ll> stk;
for (int i = 1;i <= n;i++) {
while (stk.size() && num[i] > num[stk.top()]) {
ans1[i] += ans1[stk.top()] + 1;
stk.pop();
}
stk.push(i);
}
while (stk.size())stk.pop();
for (int i = n;i >= 1;i--) {
while (stk.size() && num[i] > num[stk.top()]) {
ans2[i] += ans2[stk.top()] + 1;
stk.pop();
}
stk.push(i);
}
ll ans = 0;
map<ll, ll> vis;
for (int i = 1;i <= n;i++) {
ans += ans1[i];
}
for (int i = n;i >= 1;i--) {
if (!vis.count(num[i]))ans += ans2[i], vis[num[i]] = 1;
else vis[num[i]] = 0;
}
cout << ans << '\n';
// ll n;
// cin >> n;
// vector<ll> dp(n + 2, 0);
// vector<vector<ll>> num(n + 1, vector<ll>(n + 1, 0));
// for (int i = 1;i <= n;i++) {
// for (int j = 1;j <= i;j++) {
// cin >> num[i][j];
// }
// }
// for (int i = n;i >= 1;i--) {
// for (int j = 1;j <= i;j++) {
// dp[j] = max(dp[j], dp[j + 1]) + num[i][j];
// }
// }
// cout << dp[1] << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ll tc = 1;
cin >> tc;
while (tc--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 219ms
memory: 20348kb
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:
4084937 4130362
result:
wrong answer 1st numbers differ - expected: '4084978', found: '4084937'