QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#566941 | #9313. Make Max | Kidding_Ma | WA | 119ms | 14092kb | C++17 | 1.1kb | 2024-09-16 03:59:38 | 2024-09-16 03:59:38 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using i64 = int64_t;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
list<int> l;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
vector<int> cnt(n, 1);
vector<list<int>::iterator> d(n);
for (int i = 0; i < n; i++) {
q.emplace(a[i], i);
l.push_back(i);
d[i] = prev(l.end());
}
int ans = 0;
while (!q.empty() && l.size() > 1) {
auto [ai, i] = q.top();
q.pop();
auto it = d[i];
int j;
if (it == prev(l.end())) {
j = *prev(it);
} else {
j = *next(it);
}
cnt[j] += cnt[i];
if (a[j] != ai) {
ans += cnt[i];
}
l.erase(it);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 119ms
memory: 14092kb
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:
2276620 2350054
result:
wrong answer 1st numbers differ - expected: '4084978', found: '2276620'