zoukankan      html  css  js  c++  java
  • 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 + 500;
    const long long MAX = (1LL<<31) - 1;
    const long long MIN = -(1LL<<31);
    const long long STD = 1LL << 32;
    const long long TR = 1ll << 31;
    long long a, b , c , ans = 0  ,front = 0 , rear = 0;
    int p[maxn] , q[maxn];
    int n , m , k;
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';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 = 1 ; i <= k ; ++ i) p[i]=read();
      for(int i = k + 1 ; i <= n ; ++ i)
      {
           long long newval = 1LL * p[i-2] * a + p[i - 1] * b + c;
           if (newval < 0)
           {
               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++] = 1;
      for(int i = 2 ; i <= m ; ++ i)
       {
              while(front < rear && p[i] < p[q[rear-1]])
             rear--;
           q[rear++] = i;
       }
      ans += p[q[front]];
      for(int i = m+1 ; i <= n ; ++ i)
       {
              while(front < rear && i - q[front] >= m)
               front++;
              while(front < rear && p[i] < p[q[rear-1]])
             rear--;
           q[rear++] = i;
           ans += p[q[front]];
       }
      printf("%I64d
    ",ans);
      return 0;
    }
  • 相关阅读:
    NTP服务器搭建
    Linux安装MongoDB 4.4.2
    CentOS安装Zookeeper 3.6.2
    CentOS安装Redis 6.0.9
    MacBook Home End
    SLES Install
    cucumber soapui test web services
    S/4 HANA Solution Manager
    Linux下创建新用户
    su with hyphen and without
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4708831.html
Copyright © 2011-2022 走看看