标签:ble problem print upd reg 查询 turn tps 修改
【TimeGate】
https://www.luogu.org/problem/P3608
【解题思路】
单点修改+区间查询,用树状数组来维护f数组即可
【code】
1 #include <cstdio>
2 #include <algorithm>
3 using namespace std;
4 typedef long long LL;
5 struct Node{
6 LL h;
7 int cnt;
8 }a[100005];
9 LL ans;
10 LL b[100005],bit[100005],Maxn,n,p;
11 inline bool cmp(const Node &a,const Node &b){
12 return a.h>b.h;
13 }
14 int Sum(int x){
15 int sum=0;
16 for(int i=x;i>=1;i-=(i&(-i)))
17 sum+=bit[i];
18 return sum;
19 }
20 void Update(int x,int v){
21 for(int i=x;i<=n;i+=(i&(-i)))
22 bit[i]+=v;
23 }
24 int main(){
25 //freopen("3608.in","r",stdin);
26 //freopen("3608.out","w",stdout);
27 scanf("%lld",&n);
28 for(register int i=1;i<=n;i++){
29 scanf("%lld",&a[i].h);
30 a[i].cnt=i;
31 }
32 sort(a+1,a+n+1,cmp);
33 for(register int i=1;i<=n;i++)
34 b[a[i].cnt]=i;
35 for(register int i=1;i<=n;i++){
36 int l=Sum(b[i]);
37 int r=b[i]-l-1;
38 Update(b[i],1);
39 if(l>r*2||r>2*l)ans++;
40 }
41 printf("%d\n",ans);
42 return 0;
43 }
[USACO17JAN]Balanced Photo平衡的照片
标签:ble problem print upd reg 查询 turn tps 修改
原文地址:https://www.cnblogs.com/66dzb/p/11520746.html