QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576808 | #9313. Make Max | zhlove# | WA | 85ms | 28072kb | C++20 | 3.7kb | 2024-09-19 22:35:33 | 2024-09-19 22:35:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cout << #x << " = " << x << "\n";
#define jiasu ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long LL;
typedef pair<LL, LL> PLL;
const LL N = 1e6 + 1;
const LL M = 2020;
const LL mod = 1e9 + 7;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
LL qsm(LL a, LL b, LL m)
{
LL w = 1;
a %= m;
while (b)
{
if (b & 1) w = (w * a) % m;
a = a * a % m;
b >>= 1;
}
return w;
}
LL A(LL n, LL m)
{
LL w = 1;
while (m--)
{
w = w * n;
n -= 1;
}
return w;
}
LL C(LL n, LL m)
{
LL w = 1;
m = min(m, n - m);
for (LL i = 1; i <= m; ++i)
{
w = w * (n - m + i) / i;
}
return w;
}
LL ol(LL n)
{
LL w = n;
for (int i = 2; i <= sqrt(n); ++i)
{
if (n % i == 0)
{
w = w / i * (i - 1);
while (n % i == 0) n /= i;
}
}
if (n >= 2) w = w / n * (n - 1);
return w;
}
LL a[N];
void solve()
{
LL n;
cin >> n;
LL s = 0;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
s = max(s, a[i]);
}
//sort(a + 1, a + n + 1);
priority_queue<PLL, vector<PLL>, greater<PLL>> p;
PLL pp[N];
LL np = 0;
for (int i = 1; i <= n; ++i)
{
LL o = i;
while (a[o] == a[i] && o <= n)
o += 1;
pp[++np] = {a[i], o - i};
p.push({a[i], np});
i = o - 1;
}
LL w = 0;
while (p.size())
{
PLL x = p.top();
//cout << x.first << " " << x.second << endl;
//cout << w << endl;
LL l = x.first;
LL r = x.second;
//cout << l << endl;
if (l == s) break;
if (r == 1 && r + 1 <= np)
{
if (l < pp[r + 1].first)
{
w += pp[r].second;
pp[r + 1].second += pp[r].second;
}
p.pop();
//p.push({pp[r].first, r});
//np -= 1;
continue;
}
if (r == np && r - 1 >= 1)
{
if (l < pp[r - 1].first)
{
w += pp[r].second;
pp[r - 1].second += pp[r].second;
}
p.pop();
//p.push({pp[r].first, r});
//np -= 1;
continue;
}
if (r > 1 && r < np)
{
if (pp[r - 1].first < pp[r + 1].first)
{
if (l < pp[r + 1].first)
{
w += pp[r].second;
pp[r - 1].second += pp[r].second;
}
p.pop();
//p.push({pp[r].first, r});
//np -= 1;
continue;
}
else
{
if (l < pp[r - 1].first)
{
w += pp[r].second;
pp[r + 1].second += pp[r].second;
}
p.pop();
//p.push({pp[r].first, r});
//np -= 1;
continue;
}
}
}
cout << w << endl;
}
int main()
{
jiasu;
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 19352kb
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: 85ms
memory: 28072kb
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:
164944 158515
result:
wrong answer 1st numbers differ - expected: '4084978', found: '164944'