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. android--------性能优化之Allocation Tracker

    Allocation Tracker 能做什么? 追踪内存分配信息,按顺序排列,这样我们就能清晰看出来某一个操作的内存是如何一步一步分配出来的.比如在有内存抖动的可疑点,我们可以通过查看其内存分配轨迹 ...

  2. Kali安装nessus

    下载 在官方网站下载对应的 Nessus 版本:http://www.tenable.com/products/nessus/select-your-operating-system 这里选择 Kal ...

  3. 6月4 Smarty练习增删改

    练习Smarty的增删改所需要用到的数据库名称:timu,xuanxiang,kemu,nandu,leixing,然后使用smarty模板将前端后后台分割开来: 主页后台页面:zhupm.php & ...

  4. hadoopMR自定义输入类型

    hadoop中的输入输出数据类型: BooleanWritable:标准布尔型数值 ByteWritable:单字节数值 DoubleWritable:双字节数值 FloatWritable:浮点数 ...

  5. input type="number" 时 maxlength不起作用

    给input标签添加 oninput=“if(value.length>11) value=value.slice(0,11)”

  6. c# 线程的生命周期

    对于线程而言有两种类型:前台线程,后台线程.前台与后台线程性质相同,但终止条件不同. 后台线程:在运行过程中如果宿主进程结束,线程将直接终止执行:在强制终止时,线程即终止执行不论线程代码是否执行完毕. ...

  7. jqgrid操作列循环显示三个按钮

    首先ajax取数据 $.ajax( { type: "get", url: "../../MECManage/TJYY/collect", cache: fal ...

  8. 一、Redis的学习

    一.Redis的简介 Redis是一个高性能的key-value数据库,有点像一个hashmap. Redis与其他非关系型数据库做缓存有下面几个特点: 1.Redis支持数据的持久化,可以将内存中的 ...

  9. Win10系列:UWP界面布局进阶5

    提示框 在Windows应用商店应用程序中可以使用提示框来向用户显示提示信息,例如可以通过对话框来询问用户当前需要执行的操作,还可以通过弹出窗口来显示需要注意的信息.本节将向读者介绍如何在Window ...

  10. 关于scratch导出的flash画质很差的问题解决方案

    Scratch的分辨率是480*360,因此把scratch文件转变为flash时,因影像和画质很差,把flash插入到ppt幻灯片后,影像和画质仍然得不到保证.经过不断摸索,这个问题终于得到解决,关 ...