QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#570719 | #9313. Make Max | wdw | WA | 31ms | 8016kb | C++20 | 1.7kb | 2024-09-17 17:20:19 | 2024-09-17 17:20:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define db double
const int mod = 1e9 + 7;
const int N = 1e3 + 5;
const double eps = 1e-10;
void solve() {
int n;
cin >> n;
vector<int> a(n + 5);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> p(n + 5);
vector<int> num(n + 5);
int ans = 0;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (cnt) {
if (p[cnt] > a[i]) {
p[++cnt] = a[i];
num[cnt] = 1;
} else if (p[cnt] == a[i]) {
num[cnt]++;
} else {
int l = 1, r = cnt;
while (l < r) {
int mid = (l + r) / 2;
if (p[mid] < a[i])r = mid;
else l = mid + 1;
}
for (int i = cnt; i >= l; i--) {
num[i - 1] += num[i];
ans += num[i];
}
cnt = l;
p[cnt] = a[i];
num[l]++;
if (cnt - 1 >= 1 && p[cnt - 1] == p[cnt]) {
num[cnt - 1] += num[cnt];
cnt--;
}
}
} else {
p[++cnt] = a[i];
num[cnt] = 1;
}
}
for (int i = cnt; i >= 2; i--) {
num[i - 1] += num[i];
ans += num[i];
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(0));
int T = 1;
// cout<<fixed<<setprecision(10);
cin >> T;
while (T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
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: 31ms
memory: 8016kb
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:
212084033 373142906
result:
wrong answer 1st numbers differ - expected: '4084978', found: '212084033'