HDU5475线段树定点更新
来源:互联网 发布:血源诅咒男性捏脸数据 编辑:程序博客网 时间:2024/06/08 17:20
这题就是一个线段树的定点更新,把线段树节点初始值设为一,然后输入为一时逐个按顺序添加更新,
输入为2时按照输入的y定点更新就行了,然后向上维护积值。
#include<cstdio>#include<cstring>#include<iostream>#include<string>#include<algorithm>#define LL long longusing namespace std;#define lson l, mid, root<<1#define rson mid+1, r, root<<1|1const LL N = 1e5+10;LL mod,q;LL flag[N];struct node{ LL l, r, sum;} a[N<<2];void PushUp(LL root) //把当前节点的信息更新到父节点{ a[root].sum = (a[root<<1].sum*a[root<<1|1].sum)%mod;}void build_tree(LL l, LL r, LL root){ a[root].sum=1; a[root].l = l; a[root].r = r; if(l == r) { a[root].sum=1; return; } int mid = (l + r) >> 1; build_tree(lson); build_tree(rson);}void update(LL l, LL r, LL root,LL k){ if(l == a[root].l && r == a[root].r) { a[root].sum = k; return ; } LL mid = (a[root].l + a[root].r) >> 1; if(r <= mid) update(l, r, root<<1, k); else if(l > mid) update(l, r, root<<1|1, k); else { update(lson, k); update(rson, k); } PushUp(root);}int main(){ LL T, n, l, r, cas = 0; scanf("%d",&T); while(T--) { cin>>q>>mod; build_tree(1,q,1); printf("Case #%lld:\n", ++cas); int tem=1; memset(flag,0,sizeof(flag)); for(int i=0;i<q;i++) { int x,y; scanf("%d%d",&x,&y); if(x==1) { update(tem,tem,1,y); printf("%lld\n",a[1].sum%mod); flag[i+1]=tem; tem++; } else { update(flag[y],flag[y],1,1); printf("%lld\n",a[1].sum%mod); } } } return 0;}
0 0
- HDU5475线段树定点更新
- hdu5475 线段树单点更新
- HDU5475(线段树)
- HDU5475 An easy problem 线段树单点更新
- hdu5475 An easy problem(线段树+单点更新+区间求积)
- hdu5475 An easy problem 线段树
- hdu5475 An easy problem(线段树)
- 线段树--hdu5475 An easy problem
- HDU5475——An easy problem(线段树or暴力)
- HDU5475
- [线段树] [求区间最大] [定点修改]
- hdu5475-惊了-线段树或者暴力(有时间看)
- 线段树 单点更新
- 线段树单点更新
- 线段树 单点更新
- 线段树区间更新
- 单点更新线段树
- 线段树区间更新
- 各大音乐网站接口
- 循环引用之【#import】【@class】和循环【retain】之【assign】
- Python __init.py__文件
- 关于C++中定义对象及对象初始化的方法
- java 解析生成xml
- HDU5475线段树定点更新
- C++ STL的常见用法
- [LeetCode] 6.ZigZag Conversion
- 潘鹏整理WPF(13)元素之间绑定
- 利用addChildViewController管理子视图控制器<1>
- python处理文件
- 打开fiddler之后,电脑端浏览器无法访问页面
- 1.7 CentOS7 配置AMP环境之PHP
- clean code - 错误处理