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 ...
随机推荐
- 【二叉树、堆】15轻院校赛-J-堆
原题:http://acm.zzuli.edu.cn/problem.php?cid=1099&pid=9 [描述] [输入] [输出] Sample Input 3 1 10 3 10 5 ...
- andeoid学习笔记七
Android中Broadcast的Intent大全 Api Level 3:(SDK 1.5) android.bluetooth.a2dp.intent.action.SINK_STATE_CHA ...
- Android学习笔记一
一.eclipse中的十大快捷键: 1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间的了.这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的 ...
- redis学习笔记之pipeline
redis是一个cs模式的tcp server,使用和http类似的请求响应协议.一个client可以通过一个socket连接发起多个请求命令.每个请求命令发出后client通常 会阻塞并等待redi ...
- webdriver(python)学习笔记七——多层框架定位与智能等待
多层框架或窗口定位: switch_to_frame() switch_to_window() 智能等待: implicitly_wait() 现在web应用中经常会遇到框架如(frame)或窗口(w ...
- acdream 1044
题意:有你一个草坪,草的初始高度都是100,让你用割草机割,割草机只能横着或竖着割,每次割的高度一定,问你能不能割出给定的草坪出来. 考虑任意一个草被割要么是横着要么竖着,所以任意一个草必然是它所在行 ...
- [Irving] SQL 2005/SQL 2008 备份数据库并自动删除N天前备份的脚本
以下为SQL脚本,本人以执行计划来调用,所以改成了执行命令,大家可根据自己需要改为存储过程使用 )='E:\MsBackUp\SqlAutoBackup\' --备份路径; --备份类型为全备,1为差 ...
- [原创]谷歌插件 - YE搜图助手(YeImageFinder)
最新版本:下载 版本:v1.5 更新时间:2014年10月08日 +完善了:YeImageFinder:支持在每次启用插件时,也能正常绑定右键! +完善了:每次做完动作后,就马上关闭自身! 版本:v ...
- IOS-day02_OC中类的声明
在上一个笔记中类的使用中,在编译链接的时候会有警告,原因就是我们没有对类进行声明 类的声明如下:使用关键字@interface #import <Foundation/Foundation.h& ...
- HTML 5的消息通知机制
译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs HTML 5 已经被应用到W ...