题目描述

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 intusing 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;
}

转载于:https://www.cnblogs.com/812-xiao-wen/p/10122833.html

Ascending Rating(单调队列)相关推荐

  1. Ascending Rating【HDU 6319】【单调队列】【O(N)也TLE了的原因!震惊】

    题目链接 一道单调队列的题--菜鸡如是说到(30发过这题!),竟是一个毫不起眼的小地方! 这道题的题意就是:我们先给出K长的数组,然后剩下的(N-K)的长的剩余数组部分,我们得自己补完,就是用到了它给 ...

  2. HDU 6319(单调队列)

    传送门 题面: Problem A. Ascending Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/ ...

  3. 单调队列多重背包时间复杂度O(vn)

    版权声明:本文为博主原创文章,未经博主允许不得转载. 多重背包问题: 有N种物品和容量为V的背包,若第i种物品,容量为v[i],价值为w[i],共有n[i]件.怎样装才能使背包内的物品总价值最大? 网 ...

  4. 洛谷 P2219修筑绿化带 二维单调队列~

    题目链接:https://www.luogu.org/problem/P2219 emmm调了一个上午+中午,fan 题意:从N*M的中找到一个a*b的大矩形和减去a*b中的一个与之不重边界的c*d的 ...

  5. P2216 理想的正方形 单调队列 (二维)

    题目链接:https://www.luogu.org/problem/P2216 题意:求给定n*m的矩形中所有k*k的正方形块中最大值最小值之差(极差)最小 哇,大神的思路真的很帅 单调队列对每一行 ...

  6. 点分治问题 ----------- luoguP2942 [WC2010]重建计划 [点分治 + bfs + 单调队列 + 预处理建树 + 二分 + 01分数规划]

    题目链接 解题思路: 1.对于这个Avgvalue=∑e∈sv(e)∣s∣Avgvalue = \frac{\sum_{e\in s}v(e)}{|s|}Avgvalue=∣s∣∑e∈s​v(e)​ ...

  7. 解题报告:Fake Maxpooling(单调队列求矩阵的和)

    我们不妨先把这个问题中二维的矩阵简化成一维的数列.那么现在的问题就变成了一个求连续的滑动窗口最值问题:给出一个长度为n的数列和一个长度为k(k<n)的窗口,记录滑动窗口位于每个位置下的下的最大值 ...

  8. 0x12.基本数据结构 — 队列与单调队列

    目录 一.队列 0.UVA540 团体队列 Team Queue 1.AcWing 133. 蚯蚓(模拟优先队列) 二 .单调队列 0.AcWing 135. 最大子序和(单调队列) 1.luogu ...

  9. 【题解】P1419 寻找段落(二分+单调队列)难度⭐⭐⭐★

    P1419 寻找段落 首先二分答案,即:二分最大平均值. 我们将a全部减去mid,问题转化为判断是否存在一个长度在s~t范围内的区间它的和为正,如果有说明还有更大的平均值. 用前缀和和单调队列维护. ...

最新文章

  1. matlab textsac函数,哈工大-Matlab--2013年春季学期《MATLAB语言及应用》试题
  2. html met详解转
  3. 带android小绿人的屏保相册,盘点:那些年我们追过的Android
  4. react组件放在数组中_为什么要在函数组件中使用React.memo?
  5. On the other hand, regarding Linux Mint’s
  6. LuckyFrame执行Web自动化用例
  7. sql 去除数据表中一列中字符串后边的空格...
  8. html5爆音,刻录音乐CD出现爆音的解决方法
  9. ajax是异步非阻塞,[转帖]再谈IO的异步,同步,阻塞和非阻塞
  10. matlab画散点图
  11. 一键排班软件开发心得
  12. win10右键删除多余菜单
  13. Android破解——支付宝内购破解方法总结
  14. 能力等同于学历吗?|猿代码科技
  15. Python各类库的简介(转)
  16. OSPF骨干区域和非骨干区域通信
  17. 前端笔记:Grid布局
  18. 用java实现屏幕找图
  19. 在使用pyrcc5编译二进制文件出现错误Cannot find file:和pyrcc5: No resources in resource description.
  20. hudson搭建经验总结

热门文章

  1. 怎么生成条形码?在线条形码生成器
  2. 域名解析要买服务器吗,买了域名如何进行解析?
  3. Python实现将列表按比例和数量拆分成子列表
  4. keydown 、keyup、input区别
  5. 右下角老出现windows-延续写入失败是怎么回事
  6. OpenvSwitch — Hardware Offload
  7. zz:用MSBuild.... DailyBuild和软件开发流程的东东
  8. centos scp命令
  9. 用人单位未依法出具解除劳动合同证明需要承担法律责任吗?
  10. Docker 容器入门