zoukankan      html  css  js  c++  java
  • 杭电多校第三场-A-Ascending Rating

    题目描述

    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.

    样例输入

    1
    10 6 10 5 5 5 5
    3 2 2 1 5 7 6 8 2 9
    

    样例输出

    46 11

    题意就是在长度为n的序列中找每个长度为m的字序列中的最大值和得到最大值需要更新的次数(递增序列的长度)
    
    最大值很好解决,直接单调队列维护一下就好(同 poj2823 
    
    至于更新次数,如果用单调队列从左到右维护递增序列显然是不行的(比如n=4,m=3,a[]={4,1,2,3},i=3时单调队列为{4},然后i=4的时候4出队列了,在处理第二个长度为3的字序列{1,2,3}的时候,我们发现{1,2}并没有添加进队列,无法进行处理),所以单调队列要从右往左维护递减序列,这样比当前数字小的也会加入队列,更新次数就是队列长度。

    然后我实在无法把我的代码优化到3s了……

    #include <bits/stdc++.h>
    #define eps 0.000000000001
    #define ll long long
    using namespace std;
    const int N=1e7+5;
    int n,m,k,p,q,r,mod,T;
    int que[N],a[N];
    ll Ans_a,Ans_b;
    void Get_max()
    {
        int h=0,t=0;
        for (int i=1;i<=n;++i)
        {
            while (t>h&&a[que[t-1]]<=a[i]) t--;
            que[t++]=i;
            if (i<m) continue;
            while (que[h]<i-m+1) h++;
            Ans_a=Ans_a+(a[que[h]]^(i-m+1));
        }
    }
    void Get_num()
    {
        int h=0,t=0;
        for (int i=n;i>=1;i--)
        {
            while (t>h&&a[que[t-1]]<=a[i]) t--;
            que[t++]=i;
            if (i>n-m+1) continue;
            while (que[h]>i+m-1) h++;
            Ans_b=Ans_b+((t-h)^i);
        }
    }
    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=1;i<=k;++i) scanf("%d",&a[i]);
            for(int i=k+1;i<=n;++i) a[i]=((ll)p%mod*a[i-1]%mod+(ll)q%mod*i%mod+r%mod)%mod;
    
            Ans_a=0; Ans_b=0;
            Get_max();
            Get_num();
    
            printf("%lld %lld
    ",Ans_a,Ans_b);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    linux上运行jmeter-server失败
    转:JMeter整合InfluxDB,Grafana让测试结果实时显示
    转:基于InfluxDB&Grafana的JMeter实时性能测试数据的监控和展示
    转:Linux下用Jmeter做接口测试
    关于获取IP 电脑获取准确手机获取的IP不准确
    关于MVC微信开发遇到的那些坑。
    uploadify 上传 大文件没有反映
    HTTP 错误 404.3
    关于WEBAPI 的使用 和WEBAPI CORS 的使用过程遇到的问题
    MVC4 ViewModel 存入多个Model,以及前台的显示用法。具体类名可以参数代替
  • 原文地址:https://www.cnblogs.com/tetew/p/9439468.html
Copyright © 2011-2022 走看看