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 ...
随机推荐
- 【转】iOS 通过xib自定义UITableViewCell【原创】
原文网址:http://blog.it985.com/9683.html 在使用tableView的时候,如果cell的布局过于复杂,通过代码搭建的话不够直观.并且要不停的调整位置,字体什么的.这时, ...
- Android中空格及换行
空两个字符 换行 \n
- JQuery:各种操作表单元素方法小结
来源:http://www.ido321.com/1220.html 表单元素无处不在,已然成了Web应用不可或缺的一个部分.对表单最最最常见的操作就是获取表单元素的值或者更改表单元素的值.那在JQu ...
- 如何阅读Java源码
刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动.源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比方吧, ...
- C++ 我想这样用(七)
话接前篇,继续基于对象编程语法的剩余部分: 6.类的const成员函数和const对象 const数据成员:跟const常量一样,只是一个在类里(而且是在构造函数里),一个在类外而已,都必须初始化. ...
- HDU5742:It's All In The Mind(模拟+贪心 )
题意: 给出n和m,表示n个数,之后会给出m个下标xi和值yi,a[xi]=yi,n个数是不下降的,且总和>0,要使得(x1+x2)/∑(xi)最大. 分析: 尽可能使得前两个数最大,其他数尽可 ...
- TJOI2013 DAY2
第一题:明显先处理出最终序列,然后用线段树求解.处理最终序列可以用二分加树状数组(时间复杂度log2n, 用平衡树也可以搞...). /* * Problem: TJOI2013-day2-Seque ...
- HDU ACM Eight
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 解题背景: 看到八数码问题,没有任何的想法,偶然在翻看以前做的题的时候发现解决过类似的一道题,不 ...
- Java并发控制机制详解
在一般性开发中,笔者经常看到很多同学在对待java并发开发模型中只会使用一些基础的方法.比如Volatile,synchronized.像Lock和atomic这类高级并发包很多人并不经常使用.我想大 ...
- 第二百四十九天 how can I 坚持
竟然让我跟着他们去旅游..泡温泉,滑雪..西北坡,不去白不去. 罗娜,你别把我拉黑啊.哎,不知道咋办. 晚上玩了四局LOL,全输了,伤心. 还有今天抢票没抢到. 该怎么破,12点半正好在吃饭啊. 睡觉 ...