QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#571267#9313. Make MaxRikkualWA 241ms22328kbC++141.6kb2024-09-17 21:35:232024-09-17 21:35:24

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-17 21:35:24]
  • 评测
  • 测评结果:WA
  • 用时:241ms
  • 内存:22328kb
  • [2024-09-17 21:35:23]
  • 提交

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;
}

詳細信息

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'