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 暴力的更多相关文章

  1. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  2. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  3. Codeforces Gym 100342C Problem C. Painting Cottages 暴力

    Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...

  4. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  5. Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量

    Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...

  6. Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

    Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  7. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  8. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  9. 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 ...

随机推荐

  1. 【二叉树、堆】15轻院校赛-J-堆

    原题:http://acm.zzuli.edu.cn/problem.php?cid=1099&pid=9 [描述] [输入] [输出] Sample Input 3 1 10 3 10 5 ...

  2. 【转载】两个Web.config中连接字符串中特殊字符解决方案

    userid =  test password = aps'"; 那么连接字符串的写法为: Provider=SQLOLEDB.1;Password="aps'"&quo ...

  3. Nginx源码安装及调优配置

    导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优 ...

  4. 《Python CookBook2》 第一章 文本 - 过滤字符串中不属于指定集合的字符 && 检查一个字符串是文本还是二进制

    过滤字符串中不属于指定集合的字符 任务: 给定一个需要保留的字符串的集合,构建一个过滤函数,并可将其应用于任何字符串s,函数返回一个s的拷贝,该拷贝只包含指定字符集合中的元素. 解决方案: impor ...

  5. Android 在安装完成界面,点击打开应用程序。在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开

    Android 在安装完成界面,点击打开应用程序.在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开. etong_123的专栏 - 博客频道 - CSDN.NET htt ...

  6. 常见设计模式解析和实现(C++)Prototype模式(原型模式)

    作用:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. UML结构图: 抽象基类: 1)  Prototype:虚拟基类,所有原型的基类,提供Clone接口函数 接口函数: 1)  P ...

  7. LINQ to SQL语句之Join和Order By

    Join操作 适用场景:在我们表关系中有一对一关系,一对多关系,多对多关系等.对各个表之间的关系,就用这些实现对多个表的操作. 说明:在Join操作中,分别为Join(Join查询), SelectM ...

  8. 【C++11】 lambda表达式

    i.e.int x = 10;int y = 20;int z = [&]{ x = x * x; y = y * y; return x + y;}(); 上面z后面以[]开头的为一个lam ...

  9. linux下mysql数据库的学习

    转载博客:http://freedomljtt.blog.163.com/blog/static/72294949201210145441701/ ubuntu12.04 卸载和安装mysql 卸载m ...

  10. Visual Assist X 破解步骤

    1. 下载VA安装包,并点击exe文件安装(附下载地址:http://down.51cto.com/data/766817) 2. 将Visual Assist X Patch文件复制到C:\User ...