题目链接

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 LiRiFi, 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 LiRi, 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 3281403

题意:给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的更多相关文章

  1. 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树

    3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 1288  Solved: 490 ...

  2. 【BZOJ4260】 Codechef REBXOR 可持久化Trie

    看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...

  3. codechef 两题

    前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...

  4. codechef January Challenge 2014 Sereja and Graph

    题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...

  5. BZOJ3509: [CodeChef] COUNTARI

    3509: [CodeChef] COUNTARI Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 339  Solved: 85[Submit][St ...

  6. CodeChef CBAL

    题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...

  7. CodeChef FNCS

    题面:https://www.codechef.com/problems/FNCS 题解: 我们考虑对 n 个函数进行分块,设块的大小为S. 每个块内我们维护当前其所有函数值的和,以及数组中每个元素对 ...

  8. codechef Prime Distance On Tree(树分治+FFT)

    题目链接:http://www.codechef.com/problems/PRIMEDST/ 题意:给出一棵树,边长度都是1.每次任意取出两个点(u,v),他们之间的长度为素数的概率为多大? 树分治 ...

  9. BZOJ 3221: [Codechef FEB13] Obserbing the tree树上询问( 可持久化线段树 + 树链剖分 )

    树链剖分+可持久化线段树....这个一眼可以看出来, 因为可持久化所以写了标记永久化(否则就是区间修改的线段树的持久化..不会), 结果就写挂了, T得飞起...和管理员拿数据调后才发现= = 做法: ...

  10. BZOJ 3514: Codechef MARCH14 GERALD07加强版( LCT + 主席树 )

    从左到右加边, 假如+的边e形成环, 那么记下这个环上最早加入的边_e, 当且仅当询问区间的左端点> _e加入的时间, e对答案有贡献(脑补一下). 然后一开始是N个连通块, 假如有x条边有贡献 ...

随机推荐

  1. 【学术篇】luogu1558&&poj2777 色板游戏

    题目の传送门: luogu:https://www.luogu.org/problem/show?pid=1558 poj:http://poj.org/problem?id=2777 题目大意:给有 ...

  2. 04.Mybatis输出映射之ResultMap

    当实体类中的字段名与数据库中的字段名不一致时需要手动设置映射关系 在Mapper.xml中定义 <!-- resultMap最终还是要将结果映射到pojo上,type就是指定映射到哪一个pojo ...

  3. SQFREE - Square-free integers

    SQFREE - Square-free integers 求n以内,约数中不包含任意一个平方数的个数,\(n≤10^{14}\). 解 显然为约数计数问题,于是想办法转换为代数问题,不难列出 \[a ...

  4. Excel 2016在大数据分析领域有了很多的改善

    Excel 2016在大数据分析领域有了很多的改善 通常,我们会把大数据分析的整个过程分为五个阶段: 获取获取,数据分析,可视化,发布报告,应用报告. 在获取数据方面,Excel 2016相对Exce ...

  5. webservice技术--服务器端

    1.webservice实现单点登录具体逻辑为 ①软通web端作为客户端,请求wi社区后台,进行登录请求 ②wi社区后台验证t,核实无误后,走登录逻辑,直接进入欢迎页 ③如果有错误,封装错误xml,返 ...

  6. Spring SpringMVC SpringBoot SpringCloud 注解整理大全

    Spring SpringMVC SpringBoot SpringCloud 注解整理 才开的博客所以放了一篇以前整理的文档,如果有需要添加修改的地方欢迎指正,我会修改的φ(๑˃∀˂๑)♪ Spri ...

  7. https证书加密

    对称加密 浏览器向服务端发送请求时,服务端首先给浏览器发送一个秘钥,浏览器用秘钥对传输的数据进行加密后发送给浏览器,浏览器拿到加密后的数据使用秘钥进行解密 非对称加密 服务端通过rsa算法生成一个公钥 ...

  8. 【LGP4389】付公主的背包

    题目 退役前抄一道生成函数快乐一下 就是让我们做一个完全背包,但是朴素的做法显然是\(O(nm)\)的 把每一个物品搞成一个多项式,显然这个多项式所有\(v_i\)的倍数箱为\(1\),剩下的为\(0 ...

  9. C开发系列-预处理指令

    简介 OC程序执行过程,在源代码编译成0跟1的二进制文件之前.执行的指令称之为预处理指令. 所有的预处理指令都是以#开头.#import也是预处理指令.预处理指令主要分为三种 宏定义 条件编译 文件包 ...

  10. JS对象和数组深浅拷贝总结②

    在实际开发中遇到过太多次深拷贝浅拷贝的问题.总结一下~ JS数据存储和深浅拷贝实际运用① 这是之前写过的一篇文章,解决浅拷贝深拷贝的问题只说了一种方法,今天来补充一下. 介绍深拷贝和浅拷贝都在上一篇文 ...