QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566310 | #9313. Make Max | wjh111 | TL | 0ms | 0kb | C++14 | 1.6kb | 2024-09-15 23:46:54 | 2024-09-15 23:46:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int ans=0,n;
const int N=200004;
int tree[N*4],a[N];
int ls(int x){
return (x*2);
}
int rs(int x){
return (x*2+1);
}
void push(int x){
tree[x]=a[tree[ls(x)]]>=a[tree[rs(x)]]?tree[ls(x)]:tree[rs(x)];
}
int q(int pl,int pr,int p,int l,int r){
int res;
if (pl==l&&r==pr)
return tree[p];
//down(p,l,r);
int m=(l+r)/2;
if (pl<=m&&pr>m){
int s1=q(max(pl,m+1),pr,rs(p),m+1,r),s2=q(pl,min(pr,m),ls(p),l,m);
res=a[s1]>a[s2]?s1:s2;
return res;}
else{
if (pl<=m){
res=q(max(pl,m+1),pr,rs(p),m+1,r);
}
else{
res=q(pl,min(pr,m),ls(p),l,m);
}
return res;
}
}
/*int q(int pl,int pr,int p,int l,int r){
int res=0;
if (pl<=l&&r<=pr)
return tree[p];
int m=(l+r)/2;
if (pl<=m)
res+=q(pl,pr,ls(p),l,m);
if (pr>m)
res+=q(pl,pr,rs(p),m+1,r);
return res;
}*///等价的
void build(int x,int l,int r){
if (l==r){
tree[x]=r;
return ;
}
int m=(l+r)/2;
build(ls(x),l,m);
build(rs(x),m+1,r);
push(x);
return ;
}
int dfs(int a1,int b,int k){
if (b<a1){
return 0;
}
if (b==a1){
return a[b];
}
int i1=q(a1,b,1,1,n),m=a[i1];
int s1=dfs(a1,i1-1,m),s2=dfs(i1+1,b,m);
if (s1<m){
ans+=i1-a1;
}
if (s2<m){
ans+=b-i1;
}
return m;
}
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
int t;
cin>>t;
while (t--){
int i;
ans=0;
cin>>n;
for (i=1;i<=n;i++){
cin>>a[i];
}
build(1,1,n);
int m=0,i1=q(1,n,1,1,n);
cout<<i1<<" ";
if (dfs(1,i1-1,m)<m){
ans+=i1-1;
}
if (dfs(i1+1,n,m)<m){
ans+=n-i1;
}
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
2 0 1 0