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 ...
随机推荐
- .Net程序员玩转Android系列之二~Android Framework概要(1)
从windows操作系统说起 人们总是喜欢从将陌生的事物和自己所了解的东西关联起来,以加深对未知事物的了解,这一讲我们从windows操作系统说起,逐步引领带大家走入android的世界.写任何程序都 ...
- ASP.NET MVC4 新手入门教程之三 ---3.添加视图
在这一节你要修改HelloWorldController类要使用的视图模板文件来干净封装生成 HTML 响应到客户端的过程. 您将创建一个使用Razor 视图引擎介绍 ASP.NET MVC 3 的视 ...
- Java 并发(一) --- CAS
CAS 原理 先来看看下面的代码是否可以输出预期的值.开启了两个线程,是否会输出200 呢 结果由于并发的原因,结果会小于或等于200 , 原因出现在 count++; 由于这一行代码存在三个操作: ...
- Boxlayout中button改变大小
需要先设置maximunsize neuStart.setBorder(BorderFactory.createRaisedBevelBorder()); neuStart.setMaximumSiz ...
- java-IO小记
说来惭愧,工作一年多了,对io仍然不是很了解.不仅是io,还有网络,还有多线程.shame!!! 接下来的日子里,先搞多线程,再搞io,再搞网络,半年内一定要完成! 好了,今天终于搞懂了outputS ...
- php+mysql+jquery日历签到
在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式: 2.本次签到只记录本月 ...
- git 永久性设置密码
git 设置不需要输入密码 https方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受https带来的极速 设置记住密码(默认15分钟): git config --g ...
- csharp:DropDownComboxTreeView
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using Syste ...
- Bzoj1498&1416: [NOI2006]神奇的口袋
什么鬼双倍经验题??? Sol 考虑在第\(k\)次摸到\(y\)的概率 如果上次摸到\(y\),目前有\(sum\)个球,\(y\)有\(a[y]\)个,那么概率就是\(\frac{a[y]+d}{ ...
- 浅谈用于WEBGIS开发最重要的4个HTML5特性
WebGIS是GIS与Internet相结合的产物,一般Internet的开发手段都可用于WEBGIS的开发,比较流行的有Javascript.FLash,到现在应该说市面上的WEBGIS产品和具有的 ...