题目描述

Before the start of contest, there are n ICPC contestants waiting in a long queue. They are labeled by 1 to n from left to right. It can be easily found that the i-th contestant's QodeForces rating is ai.

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=0 and 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.

输入

The first line of the input contains an integer T(1≤T≤2000), denoting the number of test cases.

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.

输出

Since the output file may be very large, let's denote maxratingi and counti as the result of interval [i,i+m−1].

For each test case, you need to print a single line containing two integers A and B, where :

Note that ``⊕'' denotes binary XOR operation.

题目描述

在比赛开始之前,有很多ICPC参赛者排起了长队。它们从左到右标记为1到n。很容易发现第i位参赛者的QodeForces评级为ai。

Quailty师范大学的教练小Q很难看他们排队等候。他开始比较参赛者的评分。他会选择一个长度为m的连续间隔,比如[l,l + m-1],然后从左到右检查每个参赛者。最初,他将记下两个数字maxrating = 0和count = 0。每当他遇到一个比最大值更高等级的参赛者k时,他会将最大值更改为ak并计数到+1。

小 T也是一位等待比赛的教练。他知道小 Q不擅长计算,所以他想知道最大值和计数的正确最终值是多少。请写一个程序来找出答案。

输入

输入的第一行包含整数T(1≤T≤2000),表示测试用例的数量。

在每个测试用例中,第一行有7个整数n,m,k,p,q,r,MOD(1≤m,k≤n≤107,5≤p,q,r,MOD≤109),表示参赛者的数量,间隔的长度,以及参数k,p,q,r,MOD。

在下一行中,有k个整数a1,a2,...,ak(0≤ai≤109),表示前k个参赛者的等级。

为减少大输入,我们将使用以下生成器。最初给出数字p,q,r和MOD。然后如下产生值ai(k <i≤n):

保证Σn≤7×107且Σk≤2×106。

输出

由于输出文件可能非常大,因此我们将maxratingi和counti表示为区间[i,i + m-1]的结果。

对于每个测试用例,您需要打印包含两个整数A和B的单行,其中:

注意,“⊕”表示二进制XOR运算。

样例输入

1
10 6 10 5 5 5 5
3 2 2 1 5 7 6 8 2 9

样例输出

46 11

大致题意(这题需要语文水平:

给你一个长度为n的序列(输入只有前k个元素,k+1至n要根据他给的公式算出)。然后给你一个m,让你求序列中所有长度为m的区间内的最大值和最长上升子序列([1,m],[2,m+1],[3,m+2].......),更换次数为你在这个区间内从左到右遍历寻找最大值的最长上升子序列的长度。

思路:

首先这题的数据范围及最大值,更新次数等关键字眼不难让我们想到单调队列。

但这题正序遍历貌似不太理解,就倒着来进行单调队列,和滑动窗口极其相似。

最大值直接输出对首,最长上升子序列的长度就是单调队列的大小了。

代码:

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set> #define inf 0x7fffffff
#define rg register int using namespace std; int t,n,m,k,l,r,mod;
long long su,pi,p,q,z;
int a[10000001];
int s[10000001];
int f[10000001]; inline int qr(){
char ch;
while((ch=getchar())<'0'||ch>'9');
int res=ch^48;
while((ch=getchar())>='0'&&ch<='9')
res=res*10+(ch^48);
return res;
} int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
t=qr();
while(t--){ l=1,r=1;
for(rg i=0;i<=10;++i)
s[i]=-1;
n=qr(),m=qr(),k=qr();
p=qr(),q=qr(),z=qr();
mod=qr(); su=0,pi=0;
for(rg i=1;i<=k;++i)
a[i]=qr();
for(rg i=k+1;i<=n;++i)
a[i]=(p*a[i-1]+q*i+z)%mod;
for(rg i=n;i>=1;--i){
while(s[r]<=a[i]&&r>=l)r--;
s[++r]=a[i];f[r]=i;
while(f[l]>=i+m)l++;
if(i+m<=n+1)
su+=s[l]^i,pi+=(r-l+1)^i;
}printf("%lld %lld\n",su,pi);
}
return 0;
}

Ascending Rating(单调队列)的更多相关文章

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

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

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

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

  3. 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 ...

  4. HDU 6319 Problem A. Ascending Rating(单调队列)

    要求一个区间内的最大值和每次数过去最大值更新的次数,然后求每次的这个值异或 i 的总和. 这个序列一共有n个数,前k个直接给出来,从k+1到n个数用公式计算出来. 因为要最大值,所以就要用到单调队列, ...

  5. 2018年多校第三场第一题 A. Ascending Rating hdu6319

    比赛地址:http://acm.hdu.edu.cn/contests/contest_show.php?cid=804 题目编号:第一题 A. Ascending Rating  hdu6319 题 ...

  6. hdu多校第3场A.Ascending Rating

    Problem A. Ascending Rating Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Sub ...

  7. BestCoder Round #89 B题---Fxx and game(单调队列)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5945     问题描述 输入描述 输出描述 输入样例 输出样例 题意:中文题,不再赘述: 思路:  B ...

  8. 单调队列 && 斜率优化dp 专题

    首先得讲一下单调队列,顾名思义,单调队列就是队列中的每个元素具有单调性,如果是单调递增队列,那么每个元素都是单调递增的,反正,亦然. 那么如何对单调队列进行操作呢? 是这样的:对于单调队列而言,队首和 ...

  9. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

随机推荐

  1. 以e2e_cli为例漫谈fabric的一些基础知识点

    在刚接触fabric的时候一般都是直接跟着wiki的教程一步步安装配置,执行一系列命令,最终将其运行起来,但很多人对其中的运行流程及其基础知识点可能不是很了解.基于此今天我将以$FABRIC_ROOT ...

  2. Theory And Practice

    实践出真知,建议不要一味地看Backbone源码和网上解析,自己动手实践吧少年们! 我是一个简单的简直无可救药的小栗子~ ——Silun Wang 我的几个小问题: 1. Rocket介绍没有Todo ...

  3. Linux内核分析 计算机是如何工作的——by王玥

    1.冯诺依曼体系结构:也就是指存储程序计算机 硬件(存储程序计算机工作模式): 软件(程序员角度): 2.API:程序员与计算机的接口界面 ABI:程序与CPU的接口界面 3.X86的实现: 4.X8 ...

  4. 学习电脑编码utf-8,ansi编码的基础知识等

    大学时期就很好奇,我们所看到的文字在电脑里面是怎么记忆的,感觉不可能是文字本身,今天刚好学习java的io流知识,顺便补充了一下电脑编码知识,先看一下下面小王和小张的例子,然后思考电脑怎么存放文字?  ...

  5. Eclipse,代码中有错误,项目中却不显示红叉

    ***修改eclipse 代码提示级别1.单个项目修改项目上右键-->properties-->java compiler-->building-->enable projec ...

  6. ElasticSearch 2 (17) - 深入搜索系列之部分匹配

    ElasticSearch 2 (17) - 深入搜索系列之部分匹配 摘要 到目前为止,我们介绍的所有查询都是基于完整术语的,为了匹配,最小的单元为单个术语,我们只能查找反向索引中存在的术语. 但是, ...

  7. Aqua Data Studio 数据库开发工具

    Aqua Data Studio是一款完整IDE的数据库开发工具,它提供3种主要功能:数据查询与管理工具.比对数据工具与源控制和文件系统的整合工具.帮助你创建,编辑和执行 SQL 的管理工具脚本编写, ...

  8. (NOI2014)(bzoj3669)魔法森林

    LCT裸题,不会的可以来这里看看. 步入正题,现将边按a排序,依次加入每一条边,同时维护路径上的最小生成树上的最大边权,如果两点不连通,就直接连通. 如果两点已经连通,就将该边与路径上较小的一条比较, ...

  9. 学习Spring Boot:(十二)Mybatis 中自定义枚举转换器

    前言 在 Spring Boot 中使用 Mybatis 中遇到了字段为枚举类型,数据库存储的是枚举的值,发现它不能自动装载. 解决 内置枚举转换器 MyBatis内置了两个枚举转换器分别是:org. ...

  10. BZOJ 2663: [Beijing wc2012]灵魂宝石

    2663: [Beijing wc2012]灵魂宝石 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 261  Solved: 108[Submit][S ...