[树状数组] 洛谷 P3616 富金森林公园
来源:互联网 发布:mac 注销快捷键 编辑:程序博客网 时间:2024/04/19 17:46
达成成就 noip题想不出!
我是怎么做到想去写cdq分治加并查集的 还写不出来
数据结构学傻系列
其实是noip题
这样的话高度一样怎么办 我们把一个高度放大成一个高度区间就可以避免有相同数字了
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=400005;int c[N],maxn;inline void init(int n){ maxn=n; }inline void add(int x,int r){ for (int i=x;i;i-=i&-i) c[i]+=r;}inline int sum(int x){ int ret=0; for (int i=x;i<=maxn;i+=i&-i) ret+=c[i]; return ret; }int sx[N],icnt;int fat[N];inline int Fat(int u){ return u==fat[u]?u:fat[u]=Fat(fat[u]);}inline int Bin(int x){ int t=Fat(lower_bound(sx+1,sx+icnt+1,x)-sx); fat[t]=t+1; return t;}struct event{ int f,x,y;}eve[N];int n,m,h[N];inline bool peak(int i){ if (i==0 || i==n+1) return 0; return h[i]>h[i-1] && h[i]>=h[i+1];}inline bool vall(int i){ if (i==0 || i==n+1) return 1; return h[i]<h[i-1] && h[i]<=h[i+1];}inline void Add(int i){ if (peak(i))add(h[i],1); if (vall(i))add(h[i],-1);}inline void Del(int i){ if (peak(i))add(h[i],-1); if (vall(i))add(h[i],1);}int main(){ freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(m); for (int i=1;i<=n;i++) read(h[i]),sx[++icnt]=h[i]; h[0]=h[n+1]=-1<<30; sx[++icnt]=h[0]; sx[++icnt]=h[n+1]; for (int i=1;i<=m;i++) { read(eve[i].f); if (eve[i].f==1) read(eve[i].x),sx[++icnt]=eve[i].x; else read(eve[i].x),read(eve[i].y),sx[++icnt]=eve[i].y; } sort(sx+1,sx+icnt+1); for (int i=1;i<=icnt+1;i++) fat[i]=i; init(icnt); for (int i=0;i<=n+1;i++) h[i]=Bin(h[i]); for (int i=0;i<=n+1;i++) Add(i); for (int i=1;i<=m;i++) if (eve[i].f==1){ int _h=lower_bound(sx+1,sx+icnt+1,eve[i].x)-sx; printf("%d\n",sum(_h)); }else{ int p=eve[i].x,_h=Bin(eve[i].y); Del(p); Del(p-1); Del(p+1); h[p]=_h; Add(p); Add(p-1); Add(p+1); } return 0;}
0 1
- [树状数组] 洛谷 P3616 富金森林公园
- 洛谷[P3616] 富金森林公园【数据结构】【线段树】【树状数组】
- 洛谷P3616 富金森林公园
- P3616 富金森林公园
- 洛谷P1428 树状数组。。。
- 洛谷 模板 树状数组
- 洛谷P3374 树状数组
- 洛谷P3368 树状数组
- 树状数组,洛谷P3374 【模板】树状数组 1
- 【洛谷3368】树状数组 2 树状数组+差分
- 洛谷3368树状数组2
- 【模板】树状数组 洛谷P3374
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 关于CDN原理的一个形象例子
- Oracle多表查询
- Marvell 88E1145PHY芯片的初始化配置
- 【1】 一种齿轮的内径、外径以及齿数的测量
- 玲珑OJ 1100
- [树状数组] 洛谷 P3616 富金森林公园
- JVM原理分析
- 1002. A+B for Polynomials (25)
- Oracle基本操作
- JAXB玩转命名空间
- 中断的概念
- 双连通分量入门——UVALive
- CCF201503(2)待优化
- redis3.0集群搭建