CodeChef--EQUAKE
Earthquake in Bytetown! Situation is getting out of control!
All buildings in Bytetown stand on straight line. The buildings are numbered 0, 1, ..., N−1 from left to right.
Every hour one shake occurs. Each shake has 3 parameters: the leftmost building that was damaged during this shake, the corresponding rightmost building, and the force of the shake. Each time all the buildings in the disaster area are damaged equally. Let's consider this process in details.
At any moment every building has the number that indicates its height (may have leading zeroes). This number corresponds to some string consisting of digits. When some shake affects to the building its string circularly rotates to the left by the value of the force of the shake and its height corresponds to the value of new string. Pay attention that after rotation string may have leading zeroes. For instance: a building with height 950 got in disaster area with force 2, Then its string become 095, so height in reality is 95. If it was one more shake with force 1, then its height would become 950 again.
Major of Bytetown got some ideas how to protect residents, so sometimes he needs such kind of stats: find height of the highest building on some interval. You are given information about all the heights before the very first shake and then you get queries of two types:
- Type 0, described by 0 Li Ri Fi: Shake occurred on interval [Li, Ri] with force Fi.
- Type 1, described by 1 Li Ri: The major wants to know the biggest height on interval [Li, Ri].
Here, of course, the interval [L, R] contains all the building k such that L ≤ k ≤ R.
You want to get a promotion and promised to complete this task. Now it's time to do it!
Input
Each test file contains only one test case.
The first line of input contains an integer N denoting the number of buildings in Bytetown. The second line contains N space-separated integers A0, A1, ..., AN−1 denoting the initial height of the buildings. The third line contains an integer M denoting the number of queries. Each of next M lines starts with 0 or1, where 0 denotes a query Type 0 and 1 denotes a Type 1 query. If it's a Type 0 query then 3 integers follows Li, Ri, Fi, denoting number of the leftmost building, number of the rightmost building and force of this shake. If it's a Type 1 query then 2 integers follows Li, Ri, denoting numbers of the leftmost building and the rightmost building of necessary segment.
Output
For each Type 1 query, output an integer denoting the answer for the query without leading zeroes.
Constraints
- 1 ≤ N ≤ 800000 = 8 × 105
- 1 ≤ M ≤ 200000 = 2 × 105
- 0 ≤ Ai < 10000 = 104
- 0 ≤ Li ≤ Ri < N
- 0 ≤ Fi ≤ 60
- Ai does not have leading zeroes
Example
Input:
3
17 3140 832
8
1 0 2
0 0 2 1
1 1 2
1 0 0
0 0 2 2
1 0 2
0 1 1 1
1 0 2
Output:
3140
1403
71
832
3140Explanation
The initial array: [17, 3140, 832].
The first query is a Type 1 query with numbers of buildings 0 and 2, so the answer is the maximum of the array: 3140.
The second query is a Type 0 query with numbers of buildings 0 and 2, and force 1, so the array turns to:[71, 1403, 328].
The third query is a Type 1 query again with numbers of buildings 1 and 2, so the answer is the maximum of 1403 and 328: 1403
题意:给n个数,有两种操作,第一种是求区间最大值,第二种是将区间的每个数都循环移动k位,比如345移动1位变成453
思路:由于数字不大于1e4,可以考虑把每个数的所以状态都记录下来,但是每个数字的位数不一定相同,所以取他们的最大公倍数12即可。
Accepted Code:
/*************************************************************************
> File Name: EQUAKE.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月02日 星期二 22时05分51秒
> Propose:
************************************************************************/
#include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ #define lson(x) (x << 1)
#define rson(x) ((x << 1) | 1)
const int MAX_N = ;
int A[MAX_N];
struct node {
int l, r;
int cnt, var[];
}tr[MAX_N*]; int rotate(int x, int k) {
int arr[], len = , res = , tmp = x;
while (tmp) {
tmp /= ;
len++;
}
for (int i = len-; i >= ; i--) arr[i] = x % , x /= ;
for (int i = k; i < len + k; i++) res = res * + arr[i%len]; return res;
} void cal(int rt) {
int tmp[];
for (int i = ; i < ; i++)
tmp[i] = tr[rt].var[(i + tr[rt].cnt) % ];
for (int i = ; i < ; i++) tr[rt].var[i] = tmp[i];
} void pushdown(int rt) {
if (tr[rt].cnt != ) {
cal(rt);
if (tr[rt].l != tr[rt].r) {
tr[lson(rt)].cnt += tr[rt].cnt;
tr[rson(rt)].cnt += tr[rt].cnt;
tr[lson(rt)].cnt %= ;
tr[rson(rt)].cnt %= ;
}
tr[rt].cnt = ;
}
} void pushup(int rt) {
for (int i = ; i < ; i++)
tr[rt].var[i] = max(tr[lson(rt)].var[i], tr[rson(rt)].var[i]);
} void build(int rt, int L, int R) {
tr[rt].l = L, tr[rt].r = R, tr[rt].cnt = ;
if (L == R) {
for (int i = ; i < ; i++)
tr[rt].var[i] = rotate(A[L], i);
return ;
}
int mid = (L + R) / ;
build(lson(rt), L, mid);
build(rson(rt), mid + , R);
pushup(rt);
} void update(int rt, int L, int R, int v) {
pushdown(rt);
if (L > tr[rt].r || R < tr[rt].l) return ; if (tr[rt].l >= L && tr[rt].r <= R) {
tr[rt].cnt += v;
tr[rt].cnt %= ;
pushdown(rt);
return ;
}
int mid = tr[lson(rt)].r;
update(lson(rt), L, R, v);
update(rson(rt), L, R, v);
pushup(rt);
} int query(int rt, int L, int R) {
pushdown(rt);
if (tr[rt].r < L || tr[rt].l > R) return -;
if (tr[rt].l >= L && tr[rt].r <= R) {
return tr[rt].var[];
} int ql = query(lson(rt), L, R);
int qr = query(rson(rt), L, R);
return max(ql, qr);
} int main(void) {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n;
for (int i = ; i < n; i++) cin >> A[i];
build(, , n - );
cin >> m;
while (m--) {
int t;
cin >> t;
if (t == ) {
int l, r, f;
cin >> l >> r >> f;
update(, l, r, f);
} else {
int l, r;
cin >> l >> r;
cout << query(, l, r) << endl;
}
} return ;
}
CodeChef--EQUAKE的更多相关文章
- 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树
3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 1288 Solved: 490 ...
- 【BZOJ4260】 Codechef REBXOR 可持久化Trie
看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...
- codechef 两题
前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...
- codechef January Challenge 2014 Sereja and Graph
题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...
- BZOJ3509: [CodeChef] COUNTARI
3509: [CodeChef] COUNTARI Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 339 Solved: 85[Submit][St ...
- CodeChef CBAL
题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...
- CodeChef FNCS
题面:https://www.codechef.com/problems/FNCS 题解: 我们考虑对 n 个函数进行分块,设块的大小为S. 每个块内我们维护当前其所有函数值的和,以及数组中每个元素对 ...
- codechef Prime Distance On Tree(树分治+FFT)
题目链接:http://www.codechef.com/problems/PRIMEDST/ 题意:给出一棵树,边长度都是1.每次任意取出两个点(u,v),他们之间的长度为素数的概率为多大? 树分治 ...
- BZOJ 3221: [Codechef FEB13] Obserbing the tree树上询问( 可持久化线段树 + 树链剖分 )
树链剖分+可持久化线段树....这个一眼可以看出来, 因为可持久化所以写了标记永久化(否则就是区间修改的线段树的持久化..不会), 结果就写挂了, T得飞起...和管理员拿数据调后才发现= = 做法: ...
- BZOJ 3514: Codechef MARCH14 GERALD07加强版( LCT + 主席树 )
从左到右加边, 假如+的边e形成环, 那么记下这个环上最早加入的边_e, 当且仅当询问区间的左端点> _e加入的时间, e对答案有贡献(脑补一下). 然后一开始是N个连通块, 假如有x条边有贡献 ...
随机推荐
- window 下mongodb 配置
1.下载mongodb-win32-x86_64-2008plus-ssl-v3.6-latest 解压到 D:\mongodb 2.cmd => path是否有环境变量 如果没有请配置 3.创 ...
- C++编程规范和编译过程详解
前言:因为c++基础打得不牢,所以准备花点时间再学一下c++的基础知识,主要是看网易云课堂里面的免费课程,把一些知识点做个笔记记下来. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- 莫烦pytorch学习笔记(二)——variable
.简介 torch.autograd.Variable是Autograd的核心类,它封装了Tensor,并整合了反向传播的相关实现 Variable和tensor的区别和联系 Variable是篮子, ...
- nc 文件的nan识别
表现形式:print()结果为 -- 打印type为numpy.ma.core.MaskedConstant 使用 if type(x) == np.ma.core.MaskedConsta ...
- hdu 4563
hdu 4563 把每个命令走的距离抽象成完全背包 枚举最后一个不是整点走完的命令 #include <iostream> #include <algorithm> #incl ...
- Django项目: 3.用户注册功能
本章内容的补充知识点 导入库的良好顺序: 1.系统库 2.django库 3.自己定义的库(第三方库) redis缓存数据库的数据调用速度快,但是不利于长时间保存. mysql用于长时间存储,但是调用 ...
- [转]在C#代码中应用Log4Net系列教程(附源代码)
Log4Net应该可以说是DotNet中最流行的开源日志组件了.以前需要苦逼写的日志类,在Log4Net中简单地配置一下就搞定了.没用过Log4Net,真心不知道原来日志组件也可以做得这么灵活,当然这 ...
- [转]Windows钩子
Windows钩子 Windows应用程序的运行模式是基于消息驱动的,任何线程只要注册了窗口类就会有一个消息队列来接收用户的输入消息和系统消息.为了取得特定线程接收或发送的消息,就要 Windows提 ...
- JZOJ P5829 HZOI 20190801 A string 线段树
JZOJ P5829 A. string 题面:https://www.cnblogs.com/Juve/articles/11286476.html 考场上想起了排序这道题:https://www. ...
- Nopi 导出设置行高
1.导出excel行显示不完整数据客户不满意,需要我们处理 ; rowNum <= sheet.LastRowNum; rowNum++) { HSSFRow currentRow = shee ...