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:
1 /************************************************************************* 2 > File Name: EQUAKE.cpp 3 > Author: Stomach_ache 4 > Mail: sudaweitong@gmail.com 5 > Created Time: 2014年09月02日 星期二 22时05分51秒 6 > Propose: 7 ************************************************************************/ 8 #include <cmath> 9 #include <string> 10 #include <cstdio> 11 #include <fstream> 12 #include <cstring> 13 #include <iostream> 14 #include <algorithm> 15 using namespace std; 16 /*Let's fight!!!*/ 17 18 #define lson(x) (x << 1) 19 #define rson(x) ((x << 1) | 1) 20 const int MAX_N = 800050; 21 int A[MAX_N]; 22 struct node { 23 int l, r; 24 int cnt, var[12]; 25 }tr[MAX_N*4]; 26 27 int rotate(int x, int k) { 28 int arr[10], len = 0, res = 0, tmp = x; 29 while (tmp) { 30 tmp /= 10; 31 len++; 32 } 33 for (int i = len-1; i >= 0; i--) arr[i] = x % 10, x /= 10; 34 for (int i = k; i < len + k; i++) res = res * 10 + arr[i%len]; 35 36 return res; 37 } 38 39 void cal(int rt) { 40 int tmp[12]; 41 for (int i = 0; i < 12; i++) 42 tmp[i] = tr[rt].var[(i + tr[rt].cnt) % 12]; 43 for (int i = 0; i < 12; i++) tr[rt].var[i] = tmp[i]; 44 } 45 46 void pushdown(int rt) { 47 if (tr[rt].cnt != 0) { 48 cal(rt); 49 if (tr[rt].l != tr[rt].r) { 50 tr[lson(rt)].cnt += tr[rt].cnt; 51 tr[rson(rt)].cnt += tr[rt].cnt; 52 tr[lson(rt)].cnt %= 12; 53 tr[rson(rt)].cnt %= 12; 54 } 55 tr[rt].cnt = 0; 56 } 57 } 58 59 void pushup(int rt) { 60 for (int i = 0; i < 12; i++) 61 tr[rt].var[i] = max(tr[lson(rt)].var[i], tr[rson(rt)].var[i]); 62 } 63 64 void build(int rt, int L, int R) { 65 tr[rt].l = L, tr[rt].r = R, tr[rt].cnt = 0; 66 if (L == R) { 67 for (int i = 0; i < 12; i++) 68 tr[rt].var[i] = rotate(A[L], i); 69 return ; 70 } 71 int mid = (L + R) / 2; 72 build(lson(rt), L, mid); 73 build(rson(rt), mid + 1, R); 74 pushup(rt); 75 } 76 77 void update(int rt, int L, int R, int v) { 78 pushdown(rt); 79 if (L > tr[rt].r || R < tr[rt].l) return ; 80 81 if (tr[rt].l >= L && tr[rt].r <= R) { 82 tr[rt].cnt += v; 83 tr[rt].cnt %= 12; 84 pushdown(rt); 85 return ; 86 } 87 int mid = tr[lson(rt)].r; 88 update(lson(rt), L, R, v); 89 update(rson(rt), L, R, v); 90 pushup(rt); 91 } 92 93 int query(int rt, int L, int R) { 94 pushdown(rt); 95 if (tr[rt].r < L || tr[rt].l > R) return -1; 96 if (tr[rt].l >= L && tr[rt].r <= R) { 97 return tr[rt].var[0]; 98 } 99 100 int ql = query(lson(rt), L, R); 101 int qr = query(rson(rt), L, R); 102 return max(ql, qr); 103 } 104 105 int main(void) { 106 ios_base::sync_with_stdio(false); 107 int n, m; 108 cin >> n; 109 for (int i = 0; i < n; i++) cin >> A[i]; 110 build(1, 0, n - 1); 111 cin >> m; 112 while (m--) { 113 int t; 114 cin >> t; 115 if (t == 0) { 116 int l, r, f; 117 cin >> l >> r >> f; 118 update(1, l, r, f); 119 } else { 120 int l, r; 121 cin >> l >> r; 122 cout << query(1, l, r) << endl; 123 } 124 } 125 126 return 0; 127 }
转载于:https://www.cnblogs.com/Stomach-ache/p/3955408.html
CodeChef--EQUAKE相关推荐
- codechef ANUCBC(背包)
题目链接: https://www.codechef.com/problems/ANUCBC 按模数进行背包 取模不要直接取,分开写,不然会T #include<cstdio> #incl ...
- CodeChef CBAL
题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...
- CFCC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- codechef INSQ15_A(hash+二分)
思路:首先计算字符串s的所有后缀的hash值,然后根据p分离的两个字符串的最长公共子串,使用二分查找.具体代码参考: https://github.com/wuli2496/OJ/blob/maste ...
- CodeChef Cards, bags and coins [DP 泛型背包]
https://www.codechef.com/problems/ANUCBC n个数字,选出其一个子集. 求有多少子集满足其中数字之和是m的倍数.n $\le$ 100000,m $\le$ 10 ...
- Codechef SEAARC Sereja and Arcs (分块、组合计数)
我现在真的什么都不会了呢...... 题目链接: https://www.codechef.com/problems/SEAARC 好吧,这题其实考察的是枚举的功力-- 题目要求的是\(ABAB\)的 ...
- Codechef SEAARC Sereja and Arcs (分块)
我现在真的什么都不会了呢...... 题目链接: https://www.codechef.com/problems/SEAARC 好吧,这题其实考察的是枚举的功力-- 题目要求的是\(ABAB\)的 ...
- Codechef TRIPS Children Trips (分块、倍增)
题目链接: https://www.codechef.com/problems/TRIPS 感觉CC有点毒瘤啊.. 题解: 首先有一个性质可能是因为太傻所以网上没人解释,然而我看了半天: 就是正序和倒 ...
- CodeChef March Lunchtime 2018 div2
地址https://www.codechef.com/LTIME58B?order=desc&sortBy=successful_submissions 简单做了一下,前三题比较水,第四题应该 ...
- [Bzoj4260]Codechef REBXOR(trie树)
4260: Codechef REBXOR Time Limit: 10 Sec Memory Limit: 256 MB Submit: 1534 Solved: 669 [Submit][St ...
最新文章
- OpenCL产业开发链
- Linux:检查当前运行级别的五种方法
- Java类的连接与初始化 (及2013阿里初始化笔试题解析)
- python之celery简单使用
- 姚文详(Joseph Yiu):《ARM Cortex-M0权威指南》中文版目录
- Codeforces Beta Round #4 (Div. 2)【完结】
- Boost:扩展分配器的测试程序
- Sql 语句收集——行转列
- eclipse dorado plugin
- SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow...
- 关于ORACLE通过file_id与block_id定位数据库对象遇到的问题的一点思考
- 快速排序的递归方式和非递归方式
- qt实现无边框窗体的拉伸和拖动(附原理)
- 获取服务器的wsdl文件,vb.net根据wsdl文件生成WebService服务器端代码
- 简单调用百度api实现车型识别
- BOM对非标制造企业成本管控的重要性
- 计算机知识竞赛拉赞助,知识竞赛活动方案策划书
- python操作微信电脑版_python 通过微信发送消息控制电脑
- 形态学重建之孔洞填充
- 干货|chrome浏览器模拟定位