QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#570925 | #9313. Make Max | SocialPanda | TL | 0ms | 3568kb | C++23 | 1.6kb | 2024-09-17 19:10:25 | 2024-09-17 19:10:26 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define PII pair<int,int>
using namespace std;
void solve() {
int ans = 0;
int n;
cin >> n;
vector<int> a(n + 2, 0x3f3f3f3f); // Fill with MAXN
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<PII> vec;
int count = 1;
for (int i = 2; i <= n + 1; i++) {
if (a[i] != a[i - 1]) {
vec.pb({a[i - 1], count});
count = 1;
} else {
count++;
}
}
set<int> unique_elements;
for (int i = 1; i <= n; i++) {
unique_elements.insert(a[i]);
}
for (auto it = unique_elements.begin(); it != unique_elements.end(); ++it) {
int tg = *it;
if (tg == *unique_elements.rbegin()) break;
for (int i = 0; i < vec.size(); i++) {
if (vec[i].fi == tg) {
ans += vec[i].se;
if (i == 0 || (i < vec.size() - 1 && vec[i + 1].fi < vec[i - 1].fi)) {
vec[i + 1].se += vec[i].se;
} else {
vec[i - 1].se += vec[i].se;
}
vec.erase(vec.begin() + i);
i--; // Adjust index after erase
}
}
}
cout << ans << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
cin >> tt;
while (tt--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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
Time Limit Exceeded
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...