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 ...
随机推荐
- C#在不同平台下DLL的引用问题
缘起 很多时候,我们需要引用在不同平台下的DLL,32位(X86)和64位(X64).如果平台错误,在C#中会引发BadImageFormatException异常. 解决思路 我们同时不能添加不同平 ...
- 初学zookeeper--自定义事件监听
zk有四种节点类型: 持久节点,持久顺序节点,临时节点,临时顺序节点. 自定义监听事件时,在节点的创建,修改,删除的方法第一行都需要加入是否监听的一个方法: //开启监听的方法.第二个参数表示是否开启 ...
- 缓存框架EhCache的简单使用
缓存框架EhCache的简单使用: 1.Spring和EhCache框架整合 1.1导入jar包 <dependencies> <dependency> <groupId ...
- linux 忘记密码
密码保存在/etc/shadow文件中 1. root 密码忘记了 1.1 重启进入单人维护模式后, 系统会主动给予root权限的bash接口, 此时再以passwd修改密码即可: 1.2 以Live ...
- 关于移动web开发过程中的”点透“问题
先说说故事发生的场景,举个栗子如下图: A是遮罩层,B是正常的DOM,C是B上的某个元素,这里是链接.场景是点击A的时候A消失,结果点到了C,页面发生了跳转,这显然不是咱想要的~ 下面我们来监测点击事 ...
- Bzoj3105:[CQOI2013]新Nim游戏
题面 传送门 Sol 也是拿出一些数,使剩下的异或起来不为\(0\) 而线性基内的数异或不出\(0\) 那么从大到小加到线性基内 然后中途为\(0\)了,就取走它 这样我们使最大的在线性基内,剩下的是 ...
- eayui grid 每一页的行号都是从1开始
问题背景: easyui 需要显示行号的时候,我们只需要设置 rownumbers: true, 但是 不管是在哪一页,行号都是从1开始,不能连续 我们在分页的 onSelectPage 函数里去执 ...
- 记录code修改
package com.hesheng.myapplication; import android.content.Context;import android.graphics.Bitmap;imp ...
- sourcemaps and persistent modification in chrome
在现代web开发中,往往我们会借助类似sass,less之类的预处理器来加快开发进度,但是随着项目的增大,你可能无法清楚明确地知道一个css rule到底是从哪个less/scss文件中编译出来的,这 ...
- SQL Server 使用 OUTPUT做数据操作记录
OUTPUT 子句 可以在数据进行增删改的时候,可以返回受影响的行.先准备一张表 create table #t ( id int identity primary key ,name ) ) go ...