• LOJ2362. 「NOIP2016」蚯蚓【单调队列】


    LINK


    思路

    良心来说这题还挺思维的
    我没看题解也不知道要这样维护

    把每次斩断的点分别放进两个队列里面
    因为要维护增长,所以可以让新进队的节点来一个负增长?
    是不是就好了?
    然后很容易发现因为在原始队列中小的数比大的数如果多增加了(k imes q)在剩下两个队列中大的分别比小的多增加大于等于(k imes q)

    然后随便维护一下


    //Author: dream_maker
    #include<bits/stdc++.h>
    using namespace std;
    //----------------------------------------------
    //typename
    typedef long long ll;
    //convenient for
    #define fu(a, b, c) for (int a = b; a <= c; ++a)
    #define fd(a, b, c) for (int a = b; a >= c; --a)
    #define fv(a, b) for (int a = 0; a < (signed)b.size(); ++a)
    //inf of different typename
    const int INF_of_int = 1e9;
    const ll INF_of_ll = 1e18;
    //fast read and write
    template <typename T>
    void Read(T &x) {
      bool w = 1;x = 0;
      char c = getchar();
      while (!isdigit(c) && c != '-') c = getchar();
      if (c == '-') w = 0, c = getchar();
      while (isdigit(c)) {
        x = (x<<1) + (x<<3) + c -'0';
        c = getchar();
      }
      if (!w) x = -x;
    }
    template <typename T>
    void Write(T x) {
      if (x < 0) {
        putchar('-');
        x = -x; 
      }
      if (x > 9) Write(x / 10);
      putchar(x % 10 + '0');
    }
    //----------------------------------------------
    const int N = 1000010;
    int n, m;
    ll q, u, v, t, a[N];
    queue<int> Q[4];
    ll find_pos() {
      int res = 0;
      if (Q[1].size() && (!res || Q[1].front() > Q[res].front())) res = 1;
      if (Q[2].size() && (!res || Q[2].front() > Q[res].front())) res = 2;
      if (Q[3].size() && (!res || Q[3].front() > Q[res].front())) res = 3;
      return res;
    }
    int main() {
      Read(n), Read(m), Read(q), Read(u), Read(v), Read(t);
      fu(i, 1, n) Read(a[i]);
      sort(a + 1, a + n + 1);
      fd(i, n, 1) Q[1].push(a[i]);
      fu(i, 1, m) {
        ll pos = find_pos(), len = Q[pos].front();
        Q[pos].pop();
        len += (i - 1) * q;
        if (i % t == 0) {
          Write(len);
          putchar(' ');
        }
        ll l = len * u / v, r = len - l;
        l -= i * q; r -= i * q;
        Q[2].push(l);
        Q[3].push(r);
      }
      putchar('
    ');
      fu(i, 1, n + m) {
        ll pos = find_pos(), len = Q[pos].front();
        Q[pos].pop();
        len += m * q;
        if (i % t == 0) {
          Write(len);
          putchar(' ');
        }
      }
      return 0;
    }
    
  • 相关阅读:
    Hadoop中Combiner的使用
    Pig与Hive的区别
    HiveQL(HiveSQL)跟普通SQL最大区别一直使用PIG,而今也需要兼顾HIVE
    pig hive 区别
    Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别
    js打包和加密
    直观的链式回调 MyPromise
    SequelizeConnectionError: Client does not support authentication protocol requested by server; consider upgrading MariaDB client
    Lost connection to MySQL server at 'reading initial communication packet',system error:0
    css display flex
  • 原文地址:https://www.cnblogs.com/dream-maker-yk/p/9784822.html
Copyright © 2020-2023  润新知