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长的连续的序列的最小和为多少

题解

直接暴力就好了= =

不要想多了,直接暴力……

代码:

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <vector>
  7. #include <stack>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <iomanip>
  12. #include <string>
  13. #include <ctime>
  14. #include <list>
  15. typedef unsigned char byte;
  16. #define pb push_back
  17. #define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
  18. #define local freopen("in.txt","r",stdin)
  19. #define pi acos(-1)
  20.  
  21. using namespace std;
  22. const int maxn = 3e7 + ;
  23. const long long MAX = (1LL<<) - ;
  24. const long long MIN = -(1LL<<);
  25. const long long STD = 1LL << ;
  26. const long long TR = 1ll << ;
  27. long long a, b , c , ans = ,front = , rear = ;
  28. int p[maxn] , q[maxn];
  29. int n , m , k;
  30. inline int read()
  31. {
  32. int x=,f=;char ch=getchar();
  33. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  34. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  35. return x*f;
  36. }
  37.  
  38. int main(int argc,char *argv[])
  39. {
  40. freopen("minima.in","r",stdin);
  41. freopen("minima.out","w",stdout);
  42. //local;
  43. //cout <<( (-7)%5) << endl;
  44. //return 0;
  45. scanf("%d%d%d%I64d%I64d%I64d",&n,&m,&k,&a,&b,&c);
  46. for(int i = ; i <= k ; ++ i) p[i]=read();
  47. for(int i = k + ; i <= n ; ++ i)
  48. {
  49. long long newval = 1LL * p[i-] * a + p[i - ] * b + c;
  50. if (newval < )
  51. {
  52. if(-newval>=STD) newval = newval % STD ;
  53. if(newval<-TR) newval+=STD;
  54. }
  55. else
  56. {
  57. if(newval>=STD) newval = newval % STD ;
  58. if(newval>=TR) newval-=STD;
  59. }
  60. p[i] = newval;
  61. }
  62. if (m > n) m = n;
  63. q[rear++] = ;
  64. for(int i = ; i <= m ; ++ i)
  65. {
  66. while(front < rear && p[i] < p[q[rear-]])
  67. rear--;
  68. q[rear++] = i;
  69. }
  70. ans += p[q[front]];
  71. for(int i = m+ ; i <= n ; ++ i)
  72. {
  73. while(front < rear && i - q[front] >= m)
  74. front++;
  75. while(front < rear && p[i] < p[q[rear-]])
  76. rear--;
  77. q[rear++] = i;
  78. ans += p[q[front]];
  79. }
  80. printf("%I64d\n",ans);
  81. return ;
  82. }

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. HDU 5429 Geometric Progression

    题意:给出一个大数数列,问是不是等比数列. 解法:拿java大数搞,注意全是0的情况也是Yes.我把公比用分数表示了,灰常麻烦,题解说只要判a[i - 1] * a[i + 1] == a[i] * ...

  2. Hadoop中OutputFormat解析

    一.OutputFormat OutputFormat描述的是MapReduce的输出格式,它主要的任务是: 1.验证job输出格式的有效性,如:检查输出的目录是否存在. 2.通过实现RecordWr ...

  3. 《Python核心编程》 第六章 序列 - 课后习题

    课后习题 6–1.字符串.string 模块中是否有一种字符串方法或者函数可以帮我鉴定一下一个字符串是否是另一个大字符串的一部分? 答:成员关系操作符(in.not in) import string ...

  4. 【STL】帮你复习STL泛型算法 一

    STL泛型算法 #include <iostream> #include <vector> #include <algorithm> #include <it ...

  5. hive UDAF

    java 程序 package com.ibeifeng.udaf; import org.apache.hadoop.hive.ql.exec.UDAF; import org.apache.had ...

  6. PHP中的替代语法

    今天看了一下wordpress的代码,里面有些少见的php替代语法, <?php else : ?> <div class="entry-content"> ...

  7. android sensor传感器系统架构初探

    http://blog.csdn.net/qianjin0703/article/details/5942579 http://blog.chinaunix.net/uid-28621021-id-3 ...

  8. URAL-1982 Electrification Plan 最小生成树

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1982 题意:无向图,给n个点,n^2条边,每条边有个一权值,其中有k个点有发电站,给出这 ...

  9. VS2012编译可在WinXP兼容程序

    VS2012需要安装Update 1补丁 在Project的属性 选择 配置属性 - 常规 - 平台工具集 - Visual Studio 2012 - Windows XP (v110_xp) 在P ...

  10. 第二百四十二天 how can I 坚持

    今天... 貌似没啥啊. 第一天带帽子上班. 还有回来买了两个柚子吃了,有点上火啊. 还有今天雾霾爆表啊,pm2.5  600多啊. 还有看了部电影<蚁人>,挺好看.希望不会出二.三.四. ...