杭电多校第三场 A Ascending Rating

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;
int n,m,t,k,p,q,r,mod;
int a[1000001];
int b[1000001];
int c[1000001];
deque<int> qx,qn;
int cnt;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d%d%d%d",&n,&m,&k,&p,&q,&r,&mod);
        for(int i=0;i<k;i++)
            scanf("%d",&a[i]);
        for(int i=k;i<n;i++)
            a[i]=(p*a[i-1]+q*i+r)%mod;
        int x=0,y=0;
        for(int i=n-1;i>=0;i--)
        {
            while(!qx.empty()&&a[i]>=a[qx.back()])
                 qx.pop_back();
            qx.push_back(i);
            if(i<=n-m)
            {
                while(!qx.empty()&&qx.front()>=i+m) qx.pop_front();
                x+=(i+1)^a[qx.front()];
                y+=(i+1)^qx.size();
            }
        }
        printf("%d %d\n",x,y);
    }

}

原文地址:https://www.cnblogs.com/Lis-/p/9393797.html

时间: 2024-08-30 15:34:48

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

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

躺了几天 终于记得来填坑了 1001 Ascending Rating   (hdoj 6319) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6319 单调队列 具体有点类似双端队列滑动窗口 题意:在一个队列中 每次都给定一个固定长度的区间 从i=1开始向后移动 每次在这个区间中进行a[i]和a[j]的比较 若a[i]<a[j] count++ 最大值更新为a[j] ,每个区间的最大值和count都分别异或i 求出分别的和 求区间最大值可以比较容易

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

题目链接 传送门 题意 给你一棵无根树,要你寻找一个根节点使得在将一条边权变为\(0\)后,离树根最远的点到根节点的距离最小. 思路 本题和求树的直径很像,不过要记得的东西有点多,且状态也很多. \(fi[u][0]\)表示在\(u\)这个结点不删边沿着子树方向能到达的最远距离,\(se[u][0]\)为第二远,\(th[u][0]\)为第三远,\(fa[u][0]\)表示沿着父亲方向能到达的最远距离,第二维为\(1\)表示删一条边能到达的距离. 不删边的转移和求树的直径转移方程基本上是一样的,

2019杭电多校第三场 1004 Distribution of books

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6606 考虑二分答案,我们二分一个值\(x\),那么要怎么来验证这个答案是否可行,考虑dp求解,设\(dp[i]\)为前i个在答案为\(x\)的情况下划分最最多组数,那么若\(dp[n] \geq k\) 则这个x可行, 很显然可以看出\(x\)是单调的,所以二分. \[dp[i] = max(dp[j]) + 1 (sum[i] - sum[j-1] \leq x)\] 如果直接采用暴力枚举的话复杂

2019杭电多校第三场 1008 K-th Closest Distance

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6621 考虑主席树,我们先将所有值离散化之后建主席树.对于每个查询\(s,t,p,k\) 我们考虑二分一个值\(mid\),考虑当前区间内,\([p-mid, p+mid]\)的值有多少个,很显然这是符合单调性的,那么我们只需要每次判断即可.时间复杂度\(O(nlog^2n)\) #include <bits/stdc++.h> #define pii pair<int, int> #d

2019 杭电多校 第三场

2019 Multi-University Training Contest 3 补题链接:2019 Multi-University Training Contest 3 1002 Blow up the city (HDU-6604) 题意 给定 \(n\) 个点和 \(m\) 条边的有向无环图,给出 \(q\) 次询问,每个询问给出 \(a\) 和 \(b\),求有多少个点,满足该点删去后 \(a\) 和 \(b\) 中至少一个点不能到达出度为 \(0\) 的点. 题解 支配树/灭绝树 拓

HDU 5742 It&#39;s All In The Mind (贪心) 2016杭电多校联合第二场

题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci

2019 杭电多校 第五场

2019 Multi-University Training Contest 5 补题链接:2019 Multi-University Training Contest 5 罚时爆炸 自闭场 1004 equation (HDU 6627) 题意: 给定一个整数 \(C\) 和 \(N\) 组 \(a_i,b_i\),求 \(∑_{i=1}^N|a_i\cdot x + b_i| = C\) 的所有解,如果有无穷多个解就输出 -1. 思路 分类讨论 分类讨论去绝对值.根据 \(b_i / a_i

杭电多校第七场 Traffic Network in Numazu

Problem Description Chika is elected mayor of Numazu. She needs to manage the traffic in this city. To manage the traffic is too hard for her. So she needs your help. You are given the map of the city -- an undirected connected weighted graph with N

[补]2019HDU杭电多校第五场H

红小豆又被奇怪的东西卡住了 参考于:思路https://www.cnblogs.com/st1vdy/p/11309280.html 样例https://www.cnblogs.com/dd-bond/p/11308155.html HDU-6631 line symmetric 多边形轴对称类问题.关于多边形轴对称目前可以公开的情报可见第一篇blog的大佬画的图,主要就是奇偶问题.本题主要思路是枚举实现找轴和验证对称,注意判自交的方式. 初步认识可以做一下hdu3902. 在下还是专注于讲心路