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

最新文章

  1. 《你必须知道的.NET》读书笔记三:体验OO之美
  2. Win7激活工具|OEM小马激活
  3. git 解决冲突
  4. NullableKey:解决Dictionary中键不能为null的问题 zt
  5. Resharper使用
  6. JAVA中的break[标签]continue[标签]用法
  7. linux常用命令系列—cp 复制文件与文件夹
  8. Canvas裁剪和Region、RegionIterator
  9. Linux下的一些常用命令(一)
  10. SpringBoot开发案例之整合Activiti工作流引擎
  11. 参数ref与out
  12. redis命令Set类型(七)
  13. List&lt;string&gt;序列化与反序列化一个小坑
  14. iptables命令
  15. 【webstorm】project目录树显示不出
  16. 怎么解决numpy和matplotlib无法安装问题
  17. BZOJ 1821 Group 部落划分 并查集
  18. Redis(一)源码安装
  19. BZOJ 3172 Tjoi2013 单词 后缀数组
  20. ColorMask

热门文章

  1. Delphi or函数的用法
  2. Oracle 课程二之Oracle数据库逻辑结构
  3. Android中获取应用程序(包)的信息----PackageManager
  4. sqlserver能否调用webservice发送短信呢?
  5. PHP $_SERVER的详细参数及说明
  6. ckeditor+jsp+spring配置图片上传
  7. JQuery插件的学习
  8. Hierarchical cluster算法介绍
  9. Google App Engine Deployment 相关问题
  10. ocp 1Z0-042 121-178题解析