QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572107 | #9313. Make Max | linheyu# | WA | 27ms | 6940kb | C++14 | 1.6kb | 2024-09-18 12:02:48 | 2024-09-18 12:02:51 |
Judging History
answer
#include <bits/stdc++.h>
#define lowbit(x) x&-x
#define ll long long
using namespace std;
const int N = 1000 + 4e5;
const int mod = 998244353;
stack<int> b;
ll a[N];
ll xa, cnt;
void init() {
while (!b.empty())
b.pop();
memset(a, 0, sizeof a);
xa = 0;
cnt = 0;
}
void solve() {
init();
ll n;
cin >> n;
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
if (b.empty()) {
b.push(t);
a[++xa] = 1;
} else if (b.top() > t) {
b.push(t);
a[++xa] = 1;
} else if (b.top() == t) {
a[xa]++;
} else if (b.top() < t) {
int flag = 0;
int m = 0; //临时变量记录梯度
while (!b.empty() && b.top() < t) {
b.pop();
m++;
}
if (!b.empty() && b.top() == t) {
flag = 1;
a[xa - m]++;
b.pop();
}
for (int i = 0; i < m; i++) {
cnt = cnt + a[xa - i] * (m - i);
if (flag) {
a[xa - i - 1] = a[xa - i - 1] + a[xa - i];
a[xa - i] = 0;
} else {
if (i != m - 1) {
a[xa - i - 1] = a[xa - i - 1] + a[xa - i];
a[xa - i] = 0;
} else {
a[xa - i]++;
}
}
}
if (flag)
xa = xa - m;
b.push(t);
}
}
for (int i = 1; i <= xa; i++) {
cnt = cnt + (i - 1) * a[i];
}
cout << cnt << "\n";
}
int main() {
std::ios::sync_with_stdio(false);//解除stdio与iostream的同步
std::cin.tie(nullptr);//接触cin与cout的绑定
// std::cout << std::fixed << std::setprecision(10);//输出double固定输出10位小数
int _t = 1;
std::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: 6696kb
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: 27ms
memory: 6940kb
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:
9800089416 9096610370
result:
wrong answer 1st numbers differ - expected: '4084978', found: '9800089416'