题目链接

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. mysql主从复制linux配置(二进制日志文件)

    安装mysql,两台机器一主(192.168.131.153),一从(192.168.131.154) 主机配置 修改主/etc/my.cnf文件 添加 #server_id=153 ###服务器id ...

  2. 代码风格JavaScript standard style与Airbnb style

    代码风格JavaScript  standard style与Airbnb style

  3. react+redux+react-redux练习项目

    一,项目目录 二.1.新建pages包,在pages中新建TodoList.js: 2.新建store包,在store包中新建store.js,reducer.js,actionCreater.js, ...

  4. leetcode-119-杨辉三角②

    题目描述: 第一次提交: class Solution: def getRow(self, rowIndex: int) -> List[int]: k = rowIndex pre = [1] ...

  5. 0823NOIP模拟测试赛后总结

    考了两场感觉虚了... NOIP模拟测试30 分着考的. 就只有T2的美妙的暴力拿分了,60分rank10,挂了. T1是一道sb题,爆零了十分遗憾. 许多人都掉进了输出格式的坑里,C没大写.少个空格 ...

  6. LUOGU P1613 跑路 (倍增floyd)

    解题思路 倍增$floyd$,首先设$f[i][j][k]$表示$i$这个点到$j$的距离能否为$2^k$,初值是如果x,y之间有边,那么$f[x][y][0]=1$.转移方程就是$f[i][j][t ...

  7. 莫烦PyTorch学习笔记(六)——批处理

    1.要点 Torch 中提供了一种帮你整理你的数据结构的好东西, 叫做 DataLoader, 我们能用它来包装自己的数据, 进行批训练. 而且批训练可以有很多种途径. 2.DataLoader Da ...

  8. System.Web.Mvc.RedirectToRouteResult.cs

    ylbtech-System.Web.Mvc.RedirectToRouteResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutr ...

  9. String类的trim() 方法

    用于删除字符串的头尾空白符. 语法:public String trim() 返回值:删除头尾空白符的字符串. public class Test {    public static void ma ...

  10. 玩转大数据系列之Apache Pig如何与Apache Solr集成(二)

    散仙,在上篇文章中介绍了,如何使用Apache Pig与Lucene集成,还不知道的道友们,可以先看下上篇,熟悉下具体的流程. 在与Lucene集成过程中,我们发现最终还要把生成的Lucene索引,拷 ...