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条边有贡献 ...
随机推荐
- opensuse 通过composer安装drush工具
由于笔者的opensuse已安装好composer,所以按照官方网站的文章 Installing/Upgrading Drush on Ubuntu,使用composer形式安装drush工具. co ...
- layui相关用法总结
1.关闭当前弹出层 parent.layer.close(parent.layer.getFrameIndex(window.name));
- 当EntityFramework爱上AutoMapper
有时候相识即是一种缘分,相爱也不需要太多的理由,一个眼神足矣,当EntityFramework遇上AutoMapper,就是如此,恋爱虽易,相处不易. 在DDD(领域驱动设计)中,使用AutoMapp ...
- PHP如何打造一个高可用高性能的网站呢?
https://blog.csdn.net/jwq101666/article/details/80162245 1. 说到高可用的话要提一下redis,用过的都知道redis是一个具备数据库特征的n ...
- 洛谷P1081——开车旅行
传送门:QAQQAQ 题意注意点: 1.是从前往后走,不能回头 2.小A小B轮流开,先小A开,而小A是到第二近的点(这点调试的时候查了好久) 3.若绝对值差相同海拔低的更近,而第一个询问若比值相同是海 ...
- windows环境下运行Elasticsearch
1.Elasticsearch下载地址:https://github.com/medcl/elasticsearch-rtf 直接下载ZIP包: 2.配置JAVA环境 jdk64位地址:jdk-win ...
- Asp.net Core Jenkins Docker 实现一键化部署
写在前面 在前段时间尝试过用Jenkins来进行asp.net core 程序在IIS上面的自动部署.大概的流程是Jenkins从git上获取代码 最开始Jenkins是放在Ubuntu的Docker ...
- 从0开始学习ssh之basedao
用于所有dao里边会有许多相同的方法,例如save,update等等.应此设计一个basedao,所有dao都继承它.这样可以省去许多工作量. basedao如下 package cn.itcast. ...
- CentOS使用rpm离线安装mariadb
本文不再更新,可能存在内容过时的情况,实时更新请移步原文地址:CentOS使用rpm离线安装mariadb: 环境: CentOS Linux release 7.6.1810 (Core) mari ...
- 从github下载项目出现yes/no的选项,无法下载项目
解决办法: # 本地执行: ssh-keygen # 将id_rsa_pub文件中公钥拷贝到github上的ssh认证 oodful@:~/Volumes/Term2 :::$cat ~/.ssh/i ...