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
- 3140
Explanation
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条边有贡献 ...
随机推荐
- 廖雪峰Java13网络编程-2Email编程-2接收Email
1接收Email协议类型 接收Email:收件人通过MUA软件把邮件从MDA抓取到本地计算机的过程. 1.1 POP3 从MUA到MDA使用最广泛的是协议是POP3 Post Office Proto ...
- vertx使用过程中浏览器端Cookie重复问题
[问题描述] 背景: 使用vertx提供的服务,使用Dispatcher做路由转发,内部通过routingcontext做请求传递及响应. 现象: 在谷歌浏览器的Network中,看到Cookie中有 ...
- Python操作MySQL以及数据库索引
目录 python操作MySQL 安装 使用 SQL注入问题 MySQL的索引 为什么使用索引 索引的种类 主键索引 唯一索引 普通索引 索引优缺点 不会命中索引的情况 explain 索引覆盖 My ...
- Django常用组件之分页器
目录 循环插入数据测试 实现分页器 视图层使用 模板层使用 循环插入数据测试 # ORM 帮我们提供了循环插入数据更快捷的方法: book_list = [] for i in range(1000) ...
- HttpUrlConnection post 乱码 终极解决方案
今天遇到了java后台模拟http请求,以POST方式传参中文乱码,google了一下,大部分是在打开的HttpURLConnection的输入流的时候设置编码(utf-8),按照设置,试了下并没有解 ...
- 深入浅出 Java Concurrency (30): 线程池 part 3 Executor 生命周期[转]
我们知道线程是有多种执行状态的,同样管理线程的线程池也有多种状态.JVM会在所有线程(非后台daemon线程)全部终止后才退出,为了节省资源和有效释放资源关闭一个线程池就显得很重要.有时候无法正确的关 ...
- https证书加密
对称加密 浏览器向服务端发送请求时,服务端首先给浏览器发送一个秘钥,浏览器用秘钥对传输的数据进行加密后发送给浏览器,浏览器拿到加密后的数据使用秘钥进行解密 非对称加密 服务端通过rsa算法生成一个公钥 ...
- Spring cloud config client获取不到配置中心的配置
Spring cloud client在配置的时候,配置文件要用 bootstrap.properties 贴几个说明的链接.但是觉得说的依然不够详细,得空详查. 链接1 链接2 链接3 原文地址:h ...
- dd- Linux必学的60个命令
1.作用 dd命令用来复制文件,并根据参数将数据转换和格式化. 2.格式 dd [options] 3.[opitions]主要参数 bs=字节:强迫 ibs=<字节>及obs=<字 ...
- [Hdu-5155] Harry And Magic Box[思维题+容斥,计数Dp]
Online Judge:Hdu5155 Label:思维题+容斥,计数Dp 题面: 题目描述 给定一个大小为\(N*M\)的神奇盒子,里面每行每列都至少有一个钻石,问可行的排列方案数.由于答案较大, ...