QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569898 | #9313. Make Max | obiwan114 | RE | 1ms | 5780kb | C++20 | 1.6kb | 2024-09-17 12:00:13 | 2024-09-17 12:00:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int MAXX = 2e5 + 10;
pii a[MAXX];
int b[MAXX];
int tr[MAXX];
int pre[MAXX];
int suf[MAXX];
int p;
int lowbit(int x){return x & (-x);}
void update(int x,int c){
while(x <= p){
tr[x] += c;
x += lowbit(x);
}
}
int query(int x){
int res = 0;
while(x){
res += tr[x];
x -= lowbit(x);
}
return res;
}
void solve(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i].first;
b[i] = a[i].first;
}
sort(b + 1,b + n + 1);
p = unique(b + 1,b + n + 1) - b - 1;
for(int i = 1;i <= p;i++)tr[i] = 0;
for(int i = 1;i <= n;i++){
a[i].second = lower_bound(b + 1,b + p + 1,a[i].first) - b;
}
for(int i = 1;i <= n;i++){
int x = a[i].second;
if(x - 1)pre[i] = query(x - 1);
else pre[i] = 0;
update(1,-pre[i]);
update(x,pre[i] + 1);
}
for(int i = 1;i <= p;i++)tr[i] = 0;
for(int i = n;i >= 1;i--){
int x = a[i].second;
if(x - 1)suf[i] = query(x - 1);
else suf[i] = 0;
update(1,-suf[i]);
update(x,suf[i] + 1);
if(i + suf[i] < n && a[i + suf[i] + 1].second == x){
suf[i] = 0;
}
}
ll ans = 0;
for(int i = 1;i <= n;i++){
ans += pre[i] + suf[i];
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5780kb
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
Runtime Error
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...