Codeforces Gym 100342E Problem E. Minima 暴力
Problem E. Minima
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100342/attachments
Description
You are given an array x[1 . . . n] and a number m. For all i from 1 to n−m+ 1 find the minimum among x[i], x[i + 1], . . . , x[i + m − 1] and return the sum of those minima.
Input
The first line of the input file contains three integer numbers: n, m and k (1 ≤ n ≤ 30 000 000, 1 ≤ m ≤ n, 2 ≤ k ≤ min(n, 1000)). The second line of the input file contains three integer numbers: a, b and c (−2 31 ≤ a, b, c ≤ 2 31 − 1). The third line of the input file contains k integer numbers: x[1], x[2], . . . , x[k] (−2 31 ≤ x[i] ≤ 2 31 − 1).
The rest of the array is calculated using the following formula: x[i] = f(a · x[i − 2] + b · x[i − 1] + c). Here f(y) returns such number −2 31 ≤ z ≤ 2 31 − 1 that y − z is divisible by 232
.
Output
Print one integer number — the sum of minima of all subarrays of length m of the given array.
Sample Input
10 3 2
1 1 0
0 1
Sample Output
33
HINT
题意
给你一个公式,然后可以推出剩下的数,然后问你m长的连续的序列的最小和为多少
题解:
直接暴力就好了= =
不要想多了,直接暴力……
代码:
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <stack>
- #include <map>
- #include <set>
- #include <queue>
- #include <iomanip>
- #include <string>
- #include <ctime>
- #include <list>
- typedef unsigned char byte;
- #define pb push_back
- #define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
- #define local freopen("in.txt","r",stdin)
- #define pi acos(-1)
- using namespace std;
- const int maxn = 3e7 + ;
- const long long MAX = (1LL<<) - ;
- const long long MIN = -(1LL<<);
- const long long STD = 1LL << ;
- const long long TR = 1ll << ;
- long long a, b , c , ans = ,front = , rear = ;
- int p[maxn] , q[maxn];
- int n , m , k;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int main(int argc,char *argv[])
- {
- freopen("minima.in","r",stdin);
- freopen("minima.out","w",stdout);
- //local;
- //cout <<( (-7)%5) << endl;
- //return 0;
- scanf("%d%d%d%I64d%I64d%I64d",&n,&m,&k,&a,&b,&c);
- for(int i = ; i <= k ; ++ i) p[i]=read();
- for(int i = k + ; i <= n ; ++ i)
- {
- long long newval = 1LL * p[i-] * a + p[i - ] * b + c;
- if (newval < )
- {
- if(-newval>=STD) newval = newval % STD ;
- if(newval<-TR) newval+=STD;
- }
- else
- {
- if(newval>=STD) newval = newval % STD ;
- if(newval>=TR) newval-=STD;
- }
- p[i] = newval;
- }
- if (m > n) m = n;
- q[rear++] = ;
- for(int i = ; i <= m ; ++ i)
- {
- while(front < rear && p[i] < p[q[rear-]])
- rear--;
- q[rear++] = i;
- }
- ans += p[q[front]];
- for(int i = m+ ; i <= n ; ++ i)
- {
- while(front < rear && i - q[front] >= m)
- front++;
- while(front < rear && p[i] < p[q[rear-]])
- rear--;
- q[rear++] = i;
- ans += p[q[front]];
- }
- printf("%I64d\n",ans);
- return ;
- }
Codeforces Gym 100342E Problem E. Minima 暴力的更多相关文章
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100342C Problem C. Painting Cottages 暴力
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...
- Codeforces Gym 100342C Problem C. Painting Cottages 转化题意
Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...
随机推荐
- HDU 5429 Geometric Progression
题意:给出一个大数数列,问是不是等比数列. 解法:拿java大数搞,注意全是0的情况也是Yes.我把公比用分数表示了,灰常麻烦,题解说只要判a[i - 1] * a[i + 1] == a[i] * ...
- Hadoop中OutputFormat解析
一.OutputFormat OutputFormat描述的是MapReduce的输出格式,它主要的任务是: 1.验证job输出格式的有效性,如:检查输出的目录是否存在. 2.通过实现RecordWr ...
- 《Python核心编程》 第六章 序列 - 课后习题
课后习题 6–1.字符串.string 模块中是否有一种字符串方法或者函数可以帮我鉴定一下一个字符串是否是另一个大字符串的一部分? 答:成员关系操作符(in.not in) import string ...
- 【STL】帮你复习STL泛型算法 一
STL泛型算法 #include <iostream> #include <vector> #include <algorithm> #include <it ...
- hive UDAF
java 程序 package com.ibeifeng.udaf; import org.apache.hadoop.hive.ql.exec.UDAF; import org.apache.had ...
- PHP中的替代语法
今天看了一下wordpress的代码,里面有些少见的php替代语法, <?php else : ?> <div class="entry-content"> ...
- android sensor传感器系统架构初探
http://blog.csdn.net/qianjin0703/article/details/5942579 http://blog.chinaunix.net/uid-28621021-id-3 ...
- URAL-1982 Electrification Plan 最小生成树
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1982 题意:无向图,给n个点,n^2条边,每条边有个一权值,其中有k个点有发电站,给出这 ...
- VS2012编译可在WinXP兼容程序
VS2012需要安装Update 1补丁 在Project的属性 选择 配置属性 - 常规 - 平台工具集 - Visual Studio 2012 - Windows XP (v110_xp) 在P ...
- 第二百四十二天 how can I 坚持
今天... 貌似没啥啊. 第一天带帽子上班. 还有回来买了两个柚子吃了,有点上火啊. 还有今天雾霾爆表啊,pm2.5 600多啊. 还有看了部电影<蚁人>,挺好看.希望不会出二.三.四. ...