This commit is contained in:
Zengtudor 2024-08-13 11:25:45 +08:00
parent 9150dd04d9
commit ba9d9526fd
5 changed files with 100091 additions and 2 deletions

8
day11/P3608/1.in Normal file
View File

@ -0,0 +1,8 @@
7
34
6
23
0
5
99
2

75
day11/P3608/P3608.cpp Normal file
View File

@ -0,0 +1,75 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Cow{
int dir;
int h;
};
const int MAX_N = 1e5+5;
Cow cow[MAX_N];
int ans=0;
struct Tree{
int t[MAX_N];
int n;
// template<typename T>
// Tree(const &)=delete;
Tree(int n):n(n){}
int lowbit(int x){
return x&(-x);
}
void update(int dir,int delta){
while(dir<=n){
t[dir]+=delta;
dir+=lowbit(dir);
}
}
int query1to(int dir){
int sum=0;
while(dir>0){
sum+=t[dir];
dir-=lowbit(dir);
}
return sum;
}
};
int readint();
signed main(){
const int n =readint();
for(int i=1;i<=n;i++){
cow[i]={
.dir=i,
.h=readint(),
};
}
sort(cow+1,cow+n+1,[](Cow a,Cow b)->bool{
return a.h>b.h;
});
Tree cmax(n);
for(int i=1;i<=n;i++){
cmax.update(cow[i].dir, 1);
int l=cmax.query1to(cow[i].dir-1);
int r = i-l-1;
if(max(l,r)>min(l,r)*2)ans++;
}
cout<<ans<<endl;
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}

100001
day11/P3608/P3608_2.in Normal file

File diff suppressed because it is too large Load Diff

1
day11/P3608/P3608_2.out Normal file
View File

@ -0,0 +1 @@
66914

View File

@ -119,5 +119,9 @@ target("P9127")
add_files("./day9/P9127/*.cpp")
target("P3374")
set_rundir("./day11/P3374/P3374.cpp")
add_files("./day11/P3374/*.cpp")
set_rundir("./day11/P3374")
add_files("./day11/P3374/*.cpp")
target("P3608")
set_rundir("./day11/P3608")
add_files("./day11/P3608/*.cpp")