[codeforces] 498D Traffic Jams in th Land
原题
简单的线段树问题。
对于题目中,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的更多相关文章
- Codeforces 498D Traffic Jams in the Land | 线段树
题目大意: 给坐标轴1~n的点,每个点有一个权值,从一个点走到下一个点需要1s,如果当前时间是权值的倍数就要多花1s 给出q组操作,C表示单点修改权值,A表示询问0时刻x出发到y的时间 题解:因为权值 ...
- CF498D:Traffic Jams in the Land——题解
https://vjudge.net/problem/CodeForces-498D http://codeforces.com/problemset/problem/498/D 题面描述: 一些国家 ...
- CF #284 div1 D. Traffic Jams in the Land 线段树
大意是有n段路,每一段路有个值a,通过每一端路需要1s,如果通过这一段路时刻t为a的倍数,则需要等待1s再走,也就是需要2s通过. 比较头疼的就是相邻两个数之间会因为数字不同制约,一开始想a的范围是2 ...
- CF498D Traffic Jams in the Land
嘟嘟嘟 题面:有n条公路一次连接着n + 1个城市,每一条公路有一个堵塞时刻a[i],如果当前时间能被a[i]整除,那么通过这条公路需要2分钟:否则需要1分钟. 现给出n条公路的a[i],以及m次操作 ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- Codeforces Round #284 (Div. 1)
A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...
- 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 ...
- Gym 100507I Traffic Jam in Flower Town (模拟)
Traffic Jam in Flower Town 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/I Description ...
随机推荐
- Web as a App(Web既APP)的概念可以提出吗?
Web as a App (WaaA),Web既APP.灵感出于SaaS.PaaS.IaaS等~ 最近在做一个PC项目,即便我的项目是to B的,用户量没那么大,但是我仍然很注重性能及用户体验,我把我 ...
- poj_3641_Pseudoprime numbers
Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). Th ...
- Delphi中DLL的创建和使用(转)
Delphi中DLL的创建和使用 1.DLL简介: 2.调用DLL: 3.创建DLL: 4.两个技巧: 5.初始化: 6.例外处理. 1.DLL简介 ...
- python学习之控制流1
配置环境:python 3.6 python编辑器:pycharm 代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- # 控制流: # 1.布尔值: ...
- 打开Vim/Vi代码高亮
由于新装Vim/Vi 默认是没有打开代码高亮配置的,就看到有朋友一次次到网上去找各种配置.其实Vim默认带来配置文件的样本的,只需拷贝过来就可使用. 在用户根目录(~)中新建vim的配置文件 .vim ...
- ubuntu下eclipse 安装记录
基本是参考:http://www.metsky.com/archives/611.html 完成. 中间遇到小问题,在此记录下,方便遇到同样问题的难友. 先说下快速打开命令行快捷键:Ctrl+Alt+ ...
- APP测试工程师面试题:之一
第六题主要流程:编写计划 → 测试用例 → 评审用例 → 执行用例 → 写BUG →测修复情况 → 上线
- 不作伪分享者决定完整分享我自学Python3的全部过程细节
不作伪分享者决定完整分享我自学Python3的全部过程细节 我不要作伪分享者 十六年前我第一次见到了电脑,并深深地爱上了它: 十二年前我第一次连上了网络,并紧紧地被它爱上. 十年前的网络是田园美景 ...
- (原)DirectX11 深度测试(有点另类)
(问到自己清楚就可) @Author: 白袍小道 @说明:转载随缘,评论随缘,询问建议看书和源码会得到更准确的答案 深度测试的来源.目的.做法 一.问题询问 我们带着一些问题去浏览一番 1.深度测试发 ...
- ssh.sh_for_ubuntu1404
#!/bin/bash sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config s ...