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/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 5943 Accepted Submission(s): 2004
Little Q, the coach of Quailty Normal University, is bored to just watch them waiting in the queue. He starts to compare the rating of the contestants. He will pick a continous interval with length m, say [l,l+m−1], and then inspect each contestant from left to right. Initially, he will write down two numbers maxrating=−1and count=0. Everytime he meets a contestant k with strictly higher rating than maxrating, he will change maxrating to ak and count to count+1.
Little T is also a coach waiting for the contest. He knows Little Q is not good at counting, so he is wondering what are the correct final value of maxrating and count. Please write a program to figure out the answer.
In each test case, there are 7 integers n,m,k,p,q,r,MOD(1≤m,k≤n≤107,5≤p,q,r,MOD≤109) in the first line, denoting the number of contestants, the length of interval, and the parameters k,p,q,r,MOD.
In the next line, there are k integers a1,a2,...,ak(0≤ai≤109), denoting the rating of the first k contestants.
To reduce the large input, we will use the following generator. The numbers p,q,r and MOD are given initially. The values ai(k<i≤n) are then produced as follows :
It is guaranteed that ∑n≤7×107 and ∑k≤2×106.
For each test case, you need to print a single line containing two integers A and B, where :
Note that ``⊕'' denotes binary XOR operation.
提议概括:
给出 N 个数的序列,求第 i 个长度为 M 的子串里的最大值与 i 的异或值 之和, 第 i 个长度为 M 的子串求的最大值的比较次数 与 i 的异或值之和;
为了简化输入样例,只给出前 K 个数,K~N个数可根据公式 ai=(p×ai−1+q×i+r)modMOD 求出;
解题思路:
用一个单调队列从后面往前面扫,队列的大小就是 需要比较交换的次数,队尾元素就是最大值。
AC code:
#include <deque>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std; const int MAXN = 1e7+;
struct data
{
LL value;
int no;
};
deque<struct data>que; LL num[MAXN];
LL N, M, K;
LL p, q, r, MOD; int main()
{
int T_case;
scanf("%d", &T_case);
while(T_case--){
que.clear();
scanf("%lld %lld %lld %lld %lld %lld %lld", &N, &M, &K, &p, &q, &r, &MOD);
for(LL i = ; i <= K; i++){
scanf("%lld", &num[i]);
} if(K < N){
for(int i = K+; i <= N; i++){
num[i] = (p*num[i-]+q*i+r)%MOD;
}
}
data it;
for(LL i = (N-M+); i <= N; i++){
if(que.empty() || que.back().value < num[i]){
it.value = num[i];
it.no = i;
que.push_back(it);
}
}
/*
while(!que.empty()){
printf("%lld ", que.front());
que.pop_front();
}
*/
LL id = (N-M)+;
//printf("id:%lld\n", id);
LL ans_A = (que.back().value^id);
LL ans_B = (que.size()^id);
for(LL i = (N-M); i >= ; i--){
if(que.back().no >= (i+M)) que.pop_back();
while(que.front().value <= num[i] && !que.empty()) que.pop_front();
it.value = num[i];
it.no = i;
que.push_front(it);
id--;
ans_A += (que.back().value^id);
ans_B += (que.size()^id);
} printf("%lld %lld\n", ans_A, ans_B);
} return ;
}
HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】的更多相关文章
- 2018.10.29 bzoj1023: [SHOI2008]cactus仙人掌图(仙人掌+单调队列优化dp)
传送门 求仙人掌的直径. 感觉不是很难. 分点在环上面和不在环上分类讨论. 不在环上直接树形dpdpdp. 然后如果在环上讨论一波. 首先对环的祖先有贡献的只有环上dfsdfsdfs序最小的点. 对答 ...
- 【单调队列优化dp】HDU 3401 Trade
http://acm.hdu.edu.cn/showproblem.php?pid=3401 [题意] 知道之后n天的股票买卖价格(api,bpi),以及每天股票买卖数量上限(asi,bsi),问他最 ...
- hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=6319 思路: 单调队列倒着维护,队列里面剩下的值的数量就是这一段区间的count值,如样例第一个区间:3 ...
- 2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/100 ...
- 2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 200 ...
- 2018 Multi-University Training Contest 4 Problem E. Matrix from Arrays 【打表+二维前缀和】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/20 ...
- 2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000 ...
- 2018 Multi-University Training Contest 4 Problem B. Harvest of Apples 【莫队+排列组合+逆元预处理技巧】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/200 ...
- 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...
随机推荐
- FTPS Firewall
989 for the FTPS data channel implicit FTPS was expected to listen on the IANA Well Known Port 990/T ...
- Python学习之环境搭建及模块引用
这是我学习Python过程积累的经验和踩过的坑,希望学习Python的新手们能尽量避免,以免不必要的时间浪费.今天也是我第一次接触Python. 基础语法看了两个晚上,所以如果没看的朋友们,抽时间先看 ...
- 在WPF中自定义控件
一, 不一定需要自定义控件在使用WPF以前,动辄使用自定义控件几乎成了惯性思维,比如需要一个带图片的按钮,但在WPF中此类任务却不需要如此大费周章,因为控件可以嵌套使用以及可以为控件外观打造一套新的样 ...
- Java - 生成keystore
有个需求,说要在生成PDF文件时加上signature.操作PDF容易,用: <dependency> <groupId>com.itextpdf</groupId> ...
- golang学习之win7下go web之revel安装
接着上回记录的win7下go环境搭建,go的开发,现在除了sublime外,LiteIDE比较推荐,下载链接 下载安装后直接打开,需要配置下go环境(本机使用的是window 386版本),如下: 打 ...
- Azure Java Libraries 入门
本指南演示了以下 Azure Java Libraries 的用法,包括设置认证.创建并使用 Azure 存储.创建并使用 Azure SQL 数据库.部署虚拟机.从 GitHub 部署 Azure ...
- springboot伪静态
在日常网站访问中,会把动态地址改造成伪静态地址. 例如: 访问新闻栏目 /col/1/,这是原有地址,如果这样访问,不利于搜索引擎检索收录,同时安全性也不是很好. 改造之后: /col/1.html. ...
- Javascript获取页面表格中的数据
var main=mygrid.gettable("11"); //表示获取非固定列的表格 var main1=mygrid.gettable("01");// ...
- JAVA SwingWorkder的使用例
最近在学习Swing,我们都知道在UI表现线程里面长时间执行操作时,画面会假死,为了能够让费时操作不影响画面表现,就需要用多线程了.首先考虑的就是Swing内部的 SwingWorkder对象,但是网 ...
- 第7章 征服CSS3选择器(下)
:enabled选择器 在Web的表单中,有些表单元素有可用(":enabled")和不可用(":disabled")状态,比如输入框,密码框,复选框等.在默认 ...