Problem Description
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=−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.
 
Input
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 :

ai=(p×ai−1+q×i+r)modMOD

It is guaranteed that ∑n≤7×107 and ∑k≤2×106.

 
Output
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 :

AB==∑i=1n−m+1(maxratingi⊕i)∑i=1n−m+1(counti⊕i)

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

 
Sample Input
1
10 6 10 5 5 5 5
3 2 2 1 5 7 6 8 2 9
 
Sample Output
46 11
 
题意:输入 n,m,k,p,q,r,MOD  输入k个数,总共有n个数,如果输入不够的话就由上面那个公式把剩下的补齐,然后区间长度为m,访问所有的长度m的区间,
我们要求每个区间的最大值变化次数 (比如 3 2 2 1 5 7        那么我们的最大值3-5-7   所以次数是3,最大值是7) 和最大值     ,然后求每个区间的变化次数和最大值分别异或第几个区间号i的累加和
 
思路:一看复杂度,只有o(n)可以过,那么就去想o(n)算法,乍一看最大值就是用一个滑动窗口可以求出来是o(n)的,但是count我们不好记录,我们可以发现count的那些最大值
其实是一个单调递增的序列,我们想怎么去维护呢,我们求最大值那么肯定就要用o(n)了,我们可不可以同时求呢,说明我的单调序列也要能尽量沿用上一个区间的值,避免遍历
我们可以回想下,求滑动窗口的时候那个队列就是存的一个以队列首为最大值的一个最长单调递减序列,那么我们怎么由递减序列变成递增序列呢,很简单,我们倒着求滑动窗口
到时候队列长度即是最大值的变化次数
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,m,t,k,p,q,r,mod;
int a[];
deque<ll> qx;
int cnt;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d%d%d%d",&n,&m,&k,&p,&q,&r,&mod);
qx.clear();
for(int i=;i<=k;i++)
scanf("%d",&a[i]);
for(int i=k+;i<=n;i++)
a[i]=(1ll*p*a[i-]+1ll*q*i+r)%mod;
ll x=,y=;
for(int i=n;i>=;i--)
{
while(!qx.empty()&&a[i]>=a[qx.front()])
qx.pop_front();
qx.push_front(i);
if(i-<=n-m)
{
while(!qx.empty()&&qx.back()>=i+m) qx.pop_back();
x+=i^a[qx.back()];
y+=i^qx.size();
}
}
printf("%lld %lld\n",x,y);
} }

杭电多校第三场 A Ascending Rating的更多相关文章

  1. 2018 Multi-University Training Contest 3 杭电多校第三场

    躺了几天 终于记得来填坑了 1001 Ascending Rating   (hdoj 6319) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6319 ...

  2. 2019年杭电多校第三场 1011题Squrirrel(HDU6613+树DP)

    题目链接 传送门 题意 给你一棵无根树,要你寻找一个根节点使得在将一条边权变为\(0\)后,离树根最远的点到根节点的距离最小. 思路 本题和求树的直径很像,不过要记得的东西有点多,且状态也很多. \( ...

  3. 2018杭电多校第三场1003(状态压缩DP)

    #include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...

  4. 2019年杭电多校第三场 1008题Game(HDU6610+带修改莫队+Nim博弈)

    题目链接 传送门 题意 给你\(n\)堆石子,每堆有\(a_i\)堆石子,\(q\)次操作: 在\([L,R]\)内有多少个子区间使得\(Alice\)(先手)在\(Nim\)博弈中获胜: 交换\(a ...

  5. [2019杭电多校第三场][hdu6609]Find the answer(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6609 大致题意是求出每个位置i最小需要将几个位置j变为0(j<i),使得$\sum_{j=1}^ ...

  6. [2019杭电多校第三场][hdu6608]Fansblog

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6608 大致题意是比p小的最大素数q,求q!%p的值. 由威尔逊定理开始推: $(p-1)!\equiv ...

  7. [2019杭电多校第三场][hdu6606]Distribution of books(线段树&&dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6606 题意为在n个数中选m(自选)个数,然后把m个数分成k块,使得每块数字之和最大的最小. 求数字和最 ...

  8. 2019杭电多校第三场hdu6608 Fansblog(威尔逊定理)

    Fansblog 题目传送门 解题思路 Q! % P = (P-1)!/(P-1)...(Q-1) % P. 因为P是质数,根据威尔逊定理,(P-1)!%P=P-1.所以答案就是(P-1)((P-1) ...

  9. 2019杭电多校第三场hdu6609 Find the answer(线段树)

    Find the answer 题目传送门 解题思路 要想变0的个数最少,显然是优先把大的变成0.所以离散化,建立一颗权值线段树,维护区间和与区间元素数量,假设至少减去k才能满足条件,查询大于等于k的 ...

随机推荐

  1. Lab 3-4

    Analyze the malware found in the file Lab03-04.exe using basic dynamic analysis tools. (This program ...

  2. drf 生成接口文档

    REST framework可以自动帮助我们生成接口文档.接口文档以网页的方式呈现. 自动接口文档能生成的是继承自APIView及其子类的视图. 一.安装依赖 REST framewrok生成接口文档 ...

  3. SSH登录服务器修改VNC的问题

    远程登陆服务器直接用 ssh hostname@ip_address 即可登陆.hostname就是自己的用户名,ip_address就是IP地址. 关于VNC使用的命令: 杀死VNC: vncser ...

  4. 解决无法安装Microsoft .Net Framework 3.5

    如果解决不了,试试我的方法吧,我也在网上找了好久,最终在本地解决了 所需工具:dism,和Net Framework 3.5,已经打包 链接:https://pan.baidu.com/s/1nKok ...

  5. Python基础之文件的初识函数

    初识函数函数定义:定义一个事情或者功能. 等到需要的时候直接去用就好了了. 那么这里定义的东西就是一个函数即函数: 对代码块和功能的封装和定义1.1常用形式: def 函数名(): 函数体1.2 函数 ...

  6. Python-Selenium中chromeDriver限制图片和Javascript加载

    我们有的时候使用Selenium会希望能够限制图片和Javascript执行,从而提高网页加载速度. options=webdriver.ChromeOptions() prefs={      'p ...

  7. MyBatis动态sql之${}和#{}区别

    前言 ​ 接触mybatis也是在今年步入社会之后,想想也半年多了,缺没时间去系统的学习,只知道大概,也是惭愧. ​ 不知道有多少刚毕业的同学和我一样,到现在还没仔仔细细去了解你每天都会见到使用到的框 ...

  8. readline与readlines之间的简单区别

    首先来探望一下readline这位女同志: 偷窥一下user.txt内容: user password buqiuen 123456 xietingfeng 123456 一.readline例子: ...

  9. 【oauth2.0】【1】简单介绍

    含义: OAuth是一个关于授权(authorization)的开放网络标准,2.0是当前版本.不是技术,而是一项资源授权协议. OAuth在"客户端"与"服务提供商&q ...

  10. python-day73--django-分页

    ''' 批量导入数据:bulk_create Booklist=[] for i in range(100): Booklist.append(Book(title="book"+ ...