hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)

Posted kls123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)相关的知识,希望对你有一定的参考价值。

链接:

http://acm.hdu.edu.cn/showproblem.php?pid=6319

 

思路:

单调队列倒着维护,队列里面剩下的值的数量就是这一段区间的count值,如样例第一个区间:3 2 2 1 5 7

单调队列倒着维护遍历一遍变成了:7 5 3 

长度为3,队首为最大值7

 

实现代码:

#include<cstdio>
using namespace std;
#define ll long long
const int M = 1e7+10;
ll  a[M],p,q,r,mod;
ll  n,m,k;
ll  lis[M],head,tail,t;
int main()
{
    scanf("%lld",&t);
    while(t--){

        scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&m,&k,&p,&q,&r,&mod);
        for(int i = 1;i <= k;i ++)
            scanf("%lld",&a[i]);
        for(int i = k + 1;i <= n;i ++)
            a[i] = ((p * a[i - 1]) % mod + q * i % mod + r) % mod;
        head = tail = 0;
        for(int i = n;i >= n-m+1;i --){
            while(head < tail&&a[lis[tail-1]] <= a[i]) -- tail;
            lis[tail++] = i;
       }
       ll A = 0,B = 0;
       A += a[lis[head]] ^ (n-m+1);
       B += (tail - head) ^ (n - m + 1);
       for(int i = n-m;i >= 1;i --){
           while(lis[head] > i + m - 1&&head < tail) ++head;
           while(head < tail&&a[lis[tail - 1]] <= a[i]) --tail;
           lis[tail++] = i;
           A += a[lis[head]] ^ i;
           B += (tail - head) ^ i;
       }
       printf("%lld %lld
",A,B);
    }
    return 0;
}

 

以上是关于hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)的主要内容,如果未能解决你的问题,请参考以下文章

hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)

hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3)

2018 Multi-University Training Contest 3 1001 / hdu6319 Problem A. Ascending Rating 单调队列,思维

HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 单调队列优化

hdu-6319-单调队列

2018 多校3 hdu 6319 6322 6324 6330