QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571267 | #9313. Make Max | Rikkual | WA | 241ms | 22328kb | C++14 | 1.6kb | 2024-09-17 21:35:23 | 2024-09-17 21:35:24 |
Judging History
answer
#include <bits/stdc++.h>
// #pragma GCC optimize(2)
#ifndef ONLINE_JUDGE
#define Debug
#endif
#define multiple_test 1
#define int int64_t
const int MAXN = 1e6, N = MAXN + 10;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f3f3f3f3fll;
using namespace std;
int a[N], b[N], dp[N];
inline void solve() {
int n; cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = i;
dp[i] = 0;
}
sort(b + 1, b + 1 + n, [](int x, int y) {
return a[x] > a[y];
});
dp[0] = dp[n + 1] = -1;
a[0] = a[n + 1] = INF;
set<int> st;
st.emplace(0); st.emplace(n + 1);
for(int k = 1; k <= n; k++) {
int i = b[k];
int nxt = *st.lower_bound(i);
int pre = *(st.lower_bound(i)--);
if(a[i] == a[nxt]) dp[i] = max(dp[i], dp[nxt]);
else dp[i] = max(dp[i], dp[nxt] + 1);
if(a[i] == a[pre]) dp[i] = max(dp[i], dp[pre]);
else dp[i] = max(dp[i], dp[pre] + 1);
st.emplace(i);
}
int res = 0;
for(int i = 1; i <= n; i++) {
res += dp[i];
// cout << dp[i] << " \n"[i == n];
}
cout << res << "\n";
}
signed main() {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
clock_t start_time = clock();
#else
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
#endif
int t = 1; if(multiple_test) cin >> t;
while(t--) {
solve();
}
#ifndef ONLINE_JUDGE
cout << "Used " << clock() - start_time << " ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7972kb
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: 241ms
memory: 22328kb
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:
2069924 1909959
result:
wrong answer 1st numbers differ - expected: '4084978', found: '2069924'