原题

简单的线段树问题。

对于题目中,a[i]的范围是26,我们仔细思考可以得出第0秒和第60秒是一样的(因为26的最小公倍数是60,),然后我们可以建一个线段树,里面记录0~59秒时刻开始通过这段所需要的时间。(如果一定要说这是60棵线段树也不是不可以……)

#include<cstdio>
#define N 100010
using namespace std;
int n,a[N],q,x,y;
char j;
struct hhh
{
int l,r,dt[65];
}tre[N*4]; int read()
{
int ans=0,fu=1;
char j=getchar();
for (;(j<'0' || j>'9') && j!='-';j=getchar()) ;
if (j=='-') fu=-1;
for (;j>='0' && j<='9';j=getchar()) ans*=10,ans+=j-'0';
return ans*fu;
} void build(int i,int l,int r)
{
tre[i].l=l;
tre[i].r=r;
if (l==r)
{
for (int t=0;t<60;t++)
if (!t || t%a[l]==0) tre[i].dt[t]=2;
else tre[i].dt[t]=1;
return ;
}
int mid=(l+r)>>1;
build(i*2,l,mid);
build(i*2+1,mid+1,r);
for (int t=0;t<60;t++)
tre[i].dt[t]=tre[i*2].dt[t]+tre[i*2+1].dt[(t+tre[i*2].dt[t])%60];
} void modify(int i,int x)
{
if (tre[i].l==tre[i].r && x==tre[i].l)
{
for (int t=0;t<60;t++)
if (t%a[x]==0) tre[i].dt[t]=2;
else tre[i].dt[t]=1;
return ;
}
int mid=(tre[i].l+tre[i].r)>>1;
if (x<=mid) modify(i*2,x);
else modify(i*2+1,x);
for (int t=0;t<60;t++)
tre[i].dt[t]=tre[i*2].dt[t]+tre[i*2+1].dt[(t+tre[i*2].dt[t])%60];
} int query(int i,int l,int r,int t)
{
if (tre[i].l==l && tre[i].r==r) return tre[i].dt[t%60];
int mid=(tre[i].l+tre[i].r)>>1;
if (r<=mid) return query(i*2,l,r,t);
if (l>mid) return query(i*2+1,l,r,t);
else
{
int p=query(i*2,l,mid,t);
p+=query(i*2+1,mid+1,r,(t+p)%60);
return p;
}
} int main()
{
n=read();
for (int i=1;i<=n;i++) a[i]=read();
build(1,1,n);
q=read();
while (q--)
{
j=getchar();
x=read();
y=read();
if (j=='C') a[x]=y,modify(1,x);
else printf("%d\n",query(1,x,y-1,0));
}
return 0;
}

[codeforces] 498D Traffic Jams in th Land的更多相关文章

  1. Codeforces 498D Traffic Jams in the Land | 线段树

    题目大意: 给坐标轴1~n的点,每个点有一个权值,从一个点走到下一个点需要1s,如果当前时间是权值的倍数就要多花1s 给出q组操作,C表示单点修改权值,A表示询问0时刻x出发到y的时间 题解:因为权值 ...

  2. CF498D:Traffic Jams in the Land——题解

    https://vjudge.net/problem/CodeForces-498D http://codeforces.com/problemset/problem/498/D 题面描述: 一些国家 ...

  3. CF #284 div1 D. Traffic Jams in the Land 线段树

    大意是有n段路,每一段路有个值a,通过每一端路需要1s,如果通过这一段路时刻t为a的倍数,则需要等待1s再走,也就是需要2s通过. 比较头疼的就是相邻两个数之间会因为数字不同制约,一开始想a的范围是2 ...

  4. CF498D Traffic Jams in the Land

    嘟嘟嘟 题面:有n条公路一次连接着n + 1个城市,每一条公路有一个堵塞时刻a[i],如果当前时间能被a[i]整除,那么通过这条公路需要2分钟:否则需要1分钟. 现给出n条公路的a[i],以及m次操作 ...

  5. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  6. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  7. Codeforces Round #284 (Div. 1)

    A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...

  8. HDU 3686 Traffic Real Time Query System(双连通分量缩点+LCA)(2010 Asia Hangzhou Regional Contest)

    Problem Description City C is really a nightmare of all drivers for its traffic jams. To solve the t ...

  9. Gym 100507I Traffic Jam in Flower Town (模拟)

    Traffic Jam in Flower Town 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/I Description ...

随机推荐

  1. vue登录插件引来的后续问题

    上次介绍了下写的登录弹框插件,过了几天发现点击去注册或者改密码的跳转失效.报错this.$router.push is not a function,继续打印this.$router也是undefin ...

  2. C++的队列和pair

    C++队列的成员函数: back()返回最后一个元素 empty()如果队列空则返回真 front()返回第一个元素 pop()删除第一个元素 push()在末尾加入一个元素 size()返回队列中元 ...

  3. Intellij IDEA 查找接口实现类的快捷键

    查找接口的实现类: IDEA 风格 ctrl + alt +B 查看类或接口的继承关系: ctrl + h 1.IDEA_查找接口的实现 的快捷键 http://blog.csdn.net/u0100 ...

  4. tcl之其他命令-eval/source

  5. array_unique() - 去除数组中重复的元素值

      array_unique() 定义和用法 array_unique() 函数移除数组中的重复的值,并返回结果数组. 当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除. 返回的数组中键名 ...

  6. Qt的QWebChannel和JS、HTML通信/交互驱动百度地图

    Qt的QWebChannel和JS.HTML通信/交互驱动百度地图 0 前言 我一个研究嵌入式的,不知道怎么就迷上了上位机,接了几个项目都是关于Qt,这个项目还是比较经典的,自己没事儿的时候也进行研究 ...

  7. QToolBox学习笔记

    抽屉控件效果类似于QQ界面 最外面一层叫工具盒QToolBox QToolBox中装的是QGroupBox,分组的盒子 在分组的盒子QGroupBox中装的是QToolButton.

  8. SGU495 概率DP

    Kids and Prizes ICPC (International Cardboard Producing Company) is in the business of producing car ...

  9. JDK及配置

    Java Jdk开发时环境,程序员使用 Jre运行时环境,用户使用 Jdk的配置 1.新建java_home   jdk的安装路径 例:C:\Program Files (x86)\Java\jdk1 ...

  10. 方法的重写(Override)与重载(Overload)的含义与区别

    1.Override(重写) 两同,两小,一大 两同:方法名相同,参数列表相同 两小:抛出的异常要小于等于父类,返回值类型要小于等于父类 一大:访问权限要大于等于父类 2.Overload(重载) 方 ...