题目链接

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 ;
}

最新文章

  1. Mac 配置 php-fpm 时出现&#39;/private/etc/php-fpm.conf&#39;: No such file or directory (2)
  2. 成熟的RosettaNet解决方案软件介绍
  3. C堆栈
  4. NSURLConnection 网络超时的那些事(转别人整理的)
  5. CSS content内容生成技术以及应用
  6. Ehcache(02)——ehcache.xml简介
  7. ADS2008 安装方法详解及文件下载
  8. 深入理解令牌认证机制(token)
  9. linux 下的read write 和fread fwrite
  10. Laravel之路由 Route::get/post/any、路由参数、过滤器、命名、子域名、前缀、与模型绑定、抛出 404 错误、控制器
  11. 【转】typedef和#define的用法与区别
  12. 【转】大数据分析中Redis怎么做到220万ops
  13. Codeforces 1053 B - Vasya and Good Sequences
  14. DataGuard 配置须知
  15. 10款CSS3按钮 - 程序员再也不用为按钮设计而发愁了...
  16. PHP——大话PHP设计模式——PSR-0规范
  17. Android 监听apk安装替换卸载广播
  18. Mina Session
  19. Vue.js中 watch 的高级用法
  20. VC++ 6.0创建MFC工程时的初级备要点(二)

热门文章

  1. 【颓废篇】easyx--2048
  2. AM历史消息及文件记录删除
  3. [转].NET Framework 4.5 五个很棒的特性
  4. HTML - 超链接标签相关
  5. 「题解」:[POJ2942]Knights of the Round Table
  6. Extjs4 似bug非bug的东西修改
  7. js遍历获取表格内数据方法
  8. PHP面向对象魔术方法之__get 和 __set函数
  9. Cesium官方教程13--Cesium和Webpack
  10. MySQL中修改多个数据表的字段拼接问题