QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568368 | #9313. Make Max | Darkmaster | WA | 0ms | 7744kb | C++14 | 1.6kb | 2024-09-16 16:13:30 | 2024-09-16 16:13:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, a[N], b[N], st[N][20][2], lg[N];
map<int, int> M;
int Max(int x, int y, int op){
int l = lg[y - x + 1];
return max(st[x][l][op], st[y - (1 << l) + 1][l][op]);
}
void solve(){
long long ans = 0;
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++) b[i] = a[n - i + 1];
lg[1] = 0;
for(int i = 2; i <= n; i ++) lg[i] = lg[i >> 1] + 1;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= lg[n]; j ++) st[i][j][0] = st[i][j][1] = 0;
for(int i = 1; i <= n; i ++) st[i][0][0] = a[i], st[i][0][1] = b[i];
for(int j = 1; j <= lg[n]; j ++)
for(int i = 1; i <= n - (1 << j) + 1; i ++)
for(int k = 0; k <= 1; k ++)
st[i][j][k] = max(st[i][j - 1][k], st[i + (1 << (j - 1))][j - 1][k]);
// for(int i = 1; i <= n; i ++){
// for(int j = i; j <= n; j ++) cout << Max(i, j, 1) << ' ';
// cout << '\n';
// }
for(int i = 1; i <= n; i ++){
int r = i + 1;
for(int j = lg[n]; j >= 0; j --){
if(r + (1 << j) - 1 <= n && Max(r, r + (1 << j) - 1, 0) < a[i])
r = r + (1 << j);
}
ans += r - i - 1;
}
// cout << ans << '\n';
for(int i = 1; i <= n; i ++){
if(M[b[i]]) continue;
M[b[i]] = 1;
int r = i + 1;
for(int j = lg[n]; j >= 0; j --){
if(r + (1 << j) - 1 <= n && Max(r, r + (1 << j) - 1, 1) < b[i])
r = r + (1 << j);
}
ans += r - i - 1;
}
M.clear();
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7744kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 0 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '0'