HDU 6319 Problem A. Ascending Rating(单调队列)
要求一个区间内的最大值和每次数过去最大值更新的次数,然后求每次的这个值异或 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(单调队列)的更多相关文章
- hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=6319 思路: 单调队列倒着维护,队列里面剩下的值的数量就是这一段区间的count值,如样例第一个区间:3 ...
- hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3)
#include <stdio.h> #include <iostream> #include <cstdlib> #include <cmath> # ...
- 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 ...
- hdu6319 Ascending Rating /// 单调队列
题目大意: 给定n m k,p q r mod, 给出序列的前k项 之后的按公式 a[i]=(p×a[i-1]+q×i+r)%mod 递推 求序列中每个长度为m的连续区间的 该区间最大值与第一位的位置 ...
- 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 ...
- HDU 6319 Ascending Rating (单调双端队列)
题意:给定一个序列a[1..n],对于每个长度为m的连续子区间,求出区间的最大值和从左往右扫描该区间最大值的变化次数. 分析:先O(n)处理出整个序列的值.求出每个长度为m的连续区间中的最大值可以用单 ...
- HDU 4123(树的直径+单调队列)
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 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 ...
- hdu 4122 Alice's mooncake shop(单调队列)
题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...
随机推荐
- Mysql drop function xxxx ERROR 1305 (42000): FUNCTION (UDF) xxxx does not exist
mysql> drop function GetEmployeeInformationByID;ERROR 1305 (42000): FUNCTION (UDF) GetEmployeeInf ...
- FAIL - Deploy Upload Failed, Exception: [org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (112503036) exceeds the configured
Message: FAIL - Deploy Upload Failed, Exception: [org.apache.tomcat.util.http.fileupload.FileUpload ...
- winform自定义控件开发
1.添加控件属性 //添加私有的控件属性 private string djm;//单据名 //添加属性描述 [Browsable(true)] [Description("djm" ...
- 通过修改Tomcat配置,解决乱码问题
贴图,问题如下: tomcat使用的默认编码方式是iso8859-1 修改tomcat下的conf/server.xml文件 找到如下代码: <Connector port="8 ...
- C#复习笔记(3)--C#2:解决C#1的问题(结束C#2的内容:最后一些特性)
结束C#2的内容:最后一些新性 这是本章要讲的内容: 分部类型:可以在多个源文件中为 一个类型编写代码. 特别适用于部分代码是自动生成, 而其他部分的代码为手写的类型. 静态类:对工具类进行整理, 以 ...
- POJ_1185_炮兵阵地 dp+状态压缩
题目:炮兵阵地 链接:http://poj.org/problem?id=1185 解题思路: 首先用 int 来表示每一行的情况,比如说第一行是k1,那么[ k1&(k1>>2) ...
- 你不知道的JavaScript——第一章:作用域是什么?
编译原理 JavaScript事实上是一门编译语言,但与传统的编译语言不同,它不是提前编译的,编译结果也不能在分布式系统中进行移植. 任何JavaScript代码片段在执行前都要进行编译(通常就在执行 ...
- mysql 如何查看sql语句执行时间和效率
查看执行时间 1 show profiles; 2 show variables;查看profiling 是否是on状态: 3 如果是off,则 set profiling = 1: 4 执行自己的s ...
- Debian下配置防火墙iptables
debian下iptables输入命令后即时生效,但重启之后配置就会消失,可用iptables-save快速保存配置,因为Debian上iptables是不会保存规则的,然后在开机自动的时候让ipta ...
- TP5上传图片
模板: <form action="{:url('Temp/addTempDo')}" enctype="multipart/form-data" met ...