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. LeetCode--414--第三大的数

    问题描述: 给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.要求算法时间复杂度必须是O(n). 示例 1: 输入: [3, 2, 1] 输出: 1 解释: 第三大的数是 1 ...

  2. uva11552

    将字符串分为len/k块.用dp[i][j]表示第i个块必须以j结尾的最小划分.当第i块没有字符j时,dp[i][j]多计一个.如果当前块只有1种字符,那么就等于dp[i-1][j].否则对于第i块的 ...

  3. 微信小程序分享

    点击链接查看详情:(转发的路径的必须写正确) https://mp.weixin.qq.com/debug/wxadoc/dev/api/share.html

  4. 小程序中this和that用法

    微信小程序中,在wx.request({});方法调用成功或者失败之后,有时候会需要获取页面初始化数据data的情况,这个时候,如果使用,this.data来获取,会出现获取不到的情况,调试页面也会报 ...

  5. 160. Intersection of Two Linked Lists(剑指Offer-两个链表的第一个公共结点)

    题目: Write a program to find the node at which the intersection of two singly linked lists begins. Fo ...

  6. 谈一谈HashMap类

    一.Java中的hashCode()和equals() 1. hashCode()的存在主要是用于查找的快捷性,如Hashtable,HashMap等,hashCode()是用来在散列存储结构中确定对 ...

  7. 模拟数据库丢失undo表空间

    数据库无事务情况下丢失undo表空间数据文件 1. 查看当前undo表空间,并删除物理undo文件 SYS@userdata>show parameter undo_tablespace; NA ...

  8. 1.Liunx 文件管理

    文件管理命令 1.基本命令:ls .cd .pwd .man 2.文件操作:touch . cp . rm . mv .ln . mkdir . rmdir 3.文件查看:cat .more .les ...

  9. ActiveMQ 处理不同类型的消息

    ActiveMQ 中的消息都继承自 org.apache.activemq.command.BaseCommand 类. broker 处理消息的调用栈如下: TransportConnection ...

  10. Linux用户创建/磁盘挂载相关命令

    命令 作用 常用参数说明 groupadd 增加用户组 -g指定组id groupmod 修饰用户组 参数和groupadd类似 groupdel 删除用户组 直接组名没参数 useradd 增加用户 ...