「HNOI2010」弹飞绵羊
「HNOI2010」弹飞绵羊
传送门
考虑分块。
每一个位置 \(i\) ,记 \(to[i]\) 表示从这个位置一直往右跳回落在哪个位置。
然后修改的时候直接暴改,查询也是暴跳,复杂度 \(O(n \sqrt n)\)
参考代码:
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rg register
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;
template < class T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while ('0' > c || c > '9') f |= c == '-', c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
}
const int _ = 200010;
int n, f[_], k[_];
int gap, pos[_], to[_], l[_ >> 1];
int main() {
#ifndef ONLINE_JUDGE
file("cpp");
#endif
read(n), gap = sqrt(n * 1.0);
for (rg int i = 1; i <= n; ++i) {
read(k[i]), pos[i] = (i - 1) / gap + 1;
if (pos[i - 1] != pos[i]) l[pos[i]] = i;
}
l[pos[n] + 1] = n + 1;
for (rg int i = n; i >= 1; --i) {
if (i + k[i] >= l[pos[i] + 1])
f[i] = 1, to[i] = i + k[i];
else
f[i] = f[i + k[i]] + 1, to[i] = to[i + k[i]];
}
int q; read(q);
for (rg int opt, x, o = 1; o <= q; ++o) {
read(opt), read(x), ++x;
if (opt == 1) {
int res = 0;
while (x <= n) res += f[x], x = to[x];
printf("%d\n", res);
} else {
read(k[x]);
for (rg int i = l[pos[x] + 1] - 1; i >= l[pos[x]]; --i) {
if (i + k[i] >= l[pos[x] + 1])
f[i] = 1, to[i] = i + k[i];
else
f[i] = f[i + k[i]] + 1, to[i] = to[i + k[i]];
}
}
}
return 0;
}
「HNOI2010」弹飞绵羊的更多相关文章
- 「HAOI2010」 弹飞绵羊
题目链接 戳我 \(Solution\) \(LCT\)裸题 我们首先先新建一个节\(n+1\)点,表示被弹飞 对于点\(i,link(i,min(n+1,i+k_i))\) 再看看修改: 现在要将点 ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 9071 Solved: 4652[Submi ...
- 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 link-cut-tree
2016-05-30 11:51:59 用一个next数组,记录点x的下一个点是哪个 查询时,moveroot(n+1),access(x),splay(x) ,输出size[ch[x][0]]即为答 ...
- 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 分块
[bzoj2002][Hnoi2010]Bounce 弹飞绵羊 2014年7月30日8101 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀 ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 LCT
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...
- bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 動態樹
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 4055 Solved: 2172[Submi ...
- bzoj 2002 : [Hnoi2010]Bounce 弹飞绵羊 (LCT)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 题面: 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: ...
- 【BZOJ2002】 [Hnoi2010]Bounce 弹飞绵羊
BZOJ2002 [Hnoi2010]Bounce 弹飞绵羊 Solution 很早以前写的一道分块题,最近在搞LCT,又做了一遍. 1.LCT做法 看到这种动态修改,想下LCT怎么维护. 修改操作就 ...
随机推荐
- linux下安装mongo数据库存
https://www.runoob.com/mongodb/mongodb-linux-install.html 安装完后,要重启一下,否则无法运行./mongod 下载完安装包,并解压 tgz(以 ...
- Spring基础篇——通过Java注解和XML配置装配bean(转载)
作者:陈本布衣 出处:http://www.cnblogs.com/chenbenbuyi 本文版权归作者和博客园共有,欢迎转载分享,但必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留 ...
- 分布式事务 --- 2PC 和 3PC
文章部分图片来自参考资料,侵删 概述 上一篇我们讲到CAP 理论,分区容错性,一致性,可用性三者不可能同时存在,而分区容错性又是客观存在的,那么为了保证可用性,我们牺牲了一致性,虽然我们保证不了强一致 ...
- python3将json数据转换到excel中
#!/usr/bin/env python# coding=utf-8# json转换为excel import xlrdimport jsonimport osfrom openpyxl impor ...
- CSS-禁止文本被选中
pc端: .not-select{ -moz-user-select:none; /*火狐*/ -webkit-user-select:none; /*webkit浏览器*/ -ms-user-sel ...
- python之requests库使用
requests库 虽然Python的标准库中 urllib模块已经包含了平常我们使用的大多数功能,但是它的 API 使用起来让人感觉不太好,而 Requests宣传是 “HTTP for Human ...
- idea抽取方法
问题:有时候一个方法里面嵌套了很多逻辑,想拆分为多个方法方便调用:或者一个方法复用性很高,这时,这个方法嵌套在局部方法里面肯定是不方便的,如何快速抽取出这个方法? public class Demo ...
- 转:建立maven私服
一.下载安装与配置 下载 到官网下载:https://www.sonatype.com/download-oss-sonatype image.png 下载的是oss3.x版本的(当时最新版), ...
- ASP.NET(C#) Json序列化反序列化帮助类Jsonhelper
原文地址:https://ken.io/note/csharp-asp.net-jsonhelper using System; using System.Collections.Generic; u ...
- POJ-3821-Dining (拆点网络流)
这题为什么不能用 左边放食物,中间放牛,后面放水? 原因很简单,假设一头牛喜欢两个食物AB和两种水AB. 此时可以从一个食物A,走到牛A,再走到水A. 但是还可以有另一条路,从另一个食物B,走到该牛A ...