要求一个区间内的最大值和每次数过去最大值更新的次数,然后求每次的这个值异或 i 的总和。

这个序列一共有n个数,前k个直接给出来,从k+1到n个数用公式计算出来。

因为要最大值,所以就要用到单调队列,然后从后往前扫一遍然后每次维护递减的单调队列。

先把从n-m+1以后开始的数放进单调队列,这时候先不操作,然后剩下的数就是要异或相加的数,然后每次的队首元素就是这个区间内的最大值,这个队列里的元素个数,其实就是更新到最大值的逆过程,也就是最大值需要更新的次数。

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
using namespace std; int T, tol;
int n, m;
ll a[maxn];
int que[maxn]; void init() {
memset(a, , sizeof a);
} int main() {
scanf("%d", &T);
while(T--) {
int k;
int p, q, r, mod;
scanf("%d%d%d%d%d%d%d", &n, &m, &k, &p, &q, &r, &mod);
for(int i=; i<=k; i++) scanf("%lld", &a[i]);
for(int i=k+; i<=n; i++) a[i] = (1ll*p*a[i-] + 1ll*q*i + r) % mod;
int head, tail;
head = tail = ;
for(int i=n; i>n-m+; i--) {
while(head != tail && a[i] >= a[que[tail-]]) tail--;
que[tail++] = i;
}
/*
for(int j=head; j<tail; j++) printf("%d %d %lld\n", i, que[j], a[que[j]]);
printf("\n");
*/
ll ans1 = ;
ll ans2 = ;
for(int i=n-m+; i>=; i--) {
while(head != tail && a[i] >= a[que[tail-]]) tail--;
que[tail++] = i;
while(i + m - < que[head]) head++;
/*
for(int j=head; j<tail; j++) printf("%d %d %lld\n", i, que[j], a[que[j]]);
printf("\n");
*/
ans1 += (a[que[head]] ^ i);
ans2 += ((tail - head) ^ i);
}
printf("%lld %lld\n", ans1, ans2);
}
return ;
}

HDU 6319 Problem A. Ascending Rating(单调队列)的更多相关文章

  1. 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. hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3)

    #include <stdio.h> #include <iostream> #include <cstdlib> #include <cmath> # ...

  3. HDU 6319.Problem A. Ascending Rating-经典滑窗问题求最大值以及COUNT-单调队列 (2018 Multi-University Training Contest 3 1001)

    2018 Multi-University Training Contest 3 6319.Problem A. Ascending Rating 题意就是给你长度为k的数列,如果数列长度k<n ...

  4. hdu6319 Ascending Rating /// 单调队列

    题目大意: 给定n m k,p q r mod, 给出序列的前k项 之后的按公式 a[i]=(p×a[i-1]+q×i+r)%mod 递推 求序列中每个长度为m的连续区间的 该区间最大值与第一位的位置 ...

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

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/500 ...

  6. HDU 6319 Ascending Rating (单调双端队列)

    题意:给定一个序列a[1..n],对于每个长度为m的连续子区间,求出区间的最大值和从左往右扫描该区间最大值的变化次数. 分析:先O(n)处理出整个序列的值.求出每个长度为m的连续区间中的最大值可以用单 ...

  7. HDU 4123(树的直径+单调队列)

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. HDU 4122 Alice's mooncake shop 单调队列优化dp

    Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  9. hdu 4122 Alice's mooncake shop(单调队列)

    题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...

随机推荐

  1. Java Core - static关键字的理解

    一.基本常识 二.关于main方法 我们最常见的static方法就是main方法,至于为什么main方法必须是static的,现在就很清楚了.因为程序在执行main方法的时候没有创建任何对象,因此只有 ...

  2. Windows 下 Mysql8.0.12 的安装方法

    1. 之前在windows 上面安装了 mysql 5.6 还有 mysql 5.7 遇到了几个坑 , 最近想直接安装最新版的 mysql 8.0.12(较新) 发现还是有坑 跟之前的版本不一样 这里 ...

  3. 数据库及ORM

    数据库概念 关系数据库编程 ORM编程

  4. Window上安装—Docker 笔记

    本文转自:http://cnodejs.org/topic/55a24267419f1e8a23a64367 需求 想玩nodeClub 源码跑起来,结果window 上各种报错,各种依赖软件要装的感 ...

  5. log4j2.xml

    <?xml version="1.0" encoding="UTF-8"?> <configuration status="info ...

  6. SSM+shiro,所有配置文件,详细注释版,自用

    spring配置文件applicationContext.xml,放在resources下 <?xml version="1.0" encoding="UTF-8& ...

  7. HTML 中的 href\src\url

    1. 2. -------from Stack Overflow <a><link>使用 href; <img><script>使用 src;

  8. SQL Server 2008 开启远程连接

    除了 IP1.IP2 外,也要把 IPALL 的端口也设置为 1433 参考:SQL Server开启1433端口,彻底解决方案

  9. opencv imdecode和imencode用法

    主要是对内存数据自动编解码 string fname = "D:/image.jpg"; //! 以二进制流方式读取图片到内存 FILE* pFile = fopen(fname. ...

  10. 页面传递的都是string ; 每个标签要有name的原因是为了取值 因为传递给后台是键值对的形式

    页面传递的都是string ; 每个标签要有name的原因是为了取值  因为传递给后台是键值对的形式