CodeForces 498 D.Traffic Jams in the Land(线段树)
来源:互联网 发布:百度指数如何导出知乎 编辑:程序博客网 时间:2024/06/06 07:33
Description
Input
第一行一个整数
Output
对于每次查询操作,输出一个答案
Sample Input
10
2 5 3 2 3 5 3 4 2 4
10
C 10 6
A 2 6
A 1 3
C 3 4
A 3 11
A 4 9
A 5 6
C 7 3
A 8 10
A 2 5
Sample Output
5
3
14
6
2
4
4
Solution
由于
用线段树维护区间和,每个区间节点维护
Code
#include<cstdio>using namespace std;#define maxn 100005#define ls (t<<1)#define rs ((t<<1)|1)int n,q,a[maxn];int Sum[maxn<<2][60];void push_up(int t){ for(int i=0;i<60;i++) Sum[t][i]=Sum[ls][i]+Sum[rs][(i+Sum[ls][i])%60];}void build(int l,int r,int t){ if(l==r) { for(int i=0;i<60;i++) if(i%a[l])Sum[t][i]=1; else Sum[t][i]=2; return ; } int mid=(l+r)/2; build(l,mid,ls),build(mid+1,r,rs); push_up(t);}void update(int x,int l,int r,int t,int v){ if(l==r) { for(int i=0;i<60;i++) if(i%v)Sum[t][i]=1; else Sum[t][i]=2; return ; } int mid=(l+r)/2; if(x<=mid)update(x,l,mid,ls,v); else update(x,mid+1,r,rs,v); push_up(t);}int query(int L,int R,int l,int r,int t,int st){ if(L<=l&&r<=R)return Sum[t][st]; int mid=(l+r)/2; if(R<=mid)return query(L,R,l,mid,ls,st); else if(L>mid)return query(L,R,mid+1,r,rs,st); else { int temp=query(L,R,l,mid,ls,st); return temp+query(L,R,mid+1,r,rs,(st+temp)%60); }}int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++)scanf("%d",&a[i]); build(1,n,1); scanf("%d",&q); while(q--) { char op[3]; int x,y; scanf("%s%d%d",op,&x,&y); if(op[0]=='A')printf("%d\n",query(x,y-1,1,n,1,0)); else update(x,1,n,1,y); } } return 0;}
阅读全文
0 0
- CodeForces 498 D.Traffic Jams in the Land(线段树)
- codeforces 498 d Traffic Jams in the Land
- CodeForces 498D Traffic Jams in the Land
- Codeforces #284 div1 D. Traffic Jams in the Land 数论 线段树
- [题解]codeforces498d Traffic Jams in the Land
- Codeforces-834D The Bakery(线段树+dp)
- Codeforces Round #441 D. Sorting the Coins(线段树)
- Codeforces 671D Roads in Yusland dfs序+线段树
- Codeforces 834D The Bakery DP(线段树维护)
- Codeforces 834D The Bakery 线段树优化DP
- Codeforces 834D The Bakery(dp+线段树)
- Codeforces 834D The Bakery【Dp+线段树】好题~
- Codeforces-834D The Bakery 线段树优化DP
- Codeforces 834D The Bakery【dp+线段树】
- Codeforces 834D The Bakery【Dp+线段树】
- codeforces 339d(线段树)
- codeforces 438D(线段树)
- Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树暴力)
- 使用java语言实现9*9乘法表
- .NET Core 2.0发布了
- 三分
- weblogic.descriptor.DescriptorException
- volatile关键字和CAS
- CodeForces 498 D.Traffic Jams in the Land(线段树)
- 解决MySQL 5.7中Your password does not satisfy the current policy requirements
- 设计模式-观察者模式
- android基础-ProgressBar及其子类和ViewAnimator及其子类
- python 日志输出格式配置
- VS namespace问题
- 搜狗2016招聘笔试题<矩阵元素相乘>Java代码(
- angular select 根据后台传回的1,2在页面显示是否,并默认选中
- MySQL索引背后的数据结构及算法原理