HBCPC 2018 网络赛H 【分块】

3人阅读 评论(0) 收藏 举报
H. GSS and OJ Submissions
time limit per test
6 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

GSS is holding a large programming contest on the website called EOJ or compileError Online Judge which is the largest programming contest platform in the world. Every day, millians of codes are submitted to the platform.

One day, someone submitted the n-th code (1 ≤ n ≤ 4 × 108), where n is GSS's lucky number, to celebrate this day, GSS is going to send a huge prize. In this case, he allocated every submission a number in [0, 264) (see the paragraph below), then he generate another number L in [1, n] . The user who submitted the submission with the L-th small number will receive the prize.

GSS allocate numbers to submissions in the following way:

typedef unsigned long long ull;
void allocate(ull A, ull B, ull s0, ull s[])
{
    s[0] = s0;
    for (int i = 1; i < n; i++) {
        s[i] = s[i - 1] * A + B;
    }
}

AB and s0 are generated elsewhere, and 0 ≤ A, B, s0 < 264. And you can assume that A, B and s0 are generated in random.

Special notice: the code above will comsume about 2 seconds or more on judger.

Now, Mingming have collected all numbers allocated to his submissions, and he wants to know weather he will win the prize. But he is too lazy to solve, so he asked you for help, please, tell him the number allocated to the submission which win the prize.

Input

Input contains 5 integers, A, B, L, n, s0.

Output

Output one line with the number —— the number allocated to the submission which win the prize.

Example
input
Copy
5 7 9 11 13
output
Copy
5761717
Note

The numbers allocated to submissions are:

13, 72, 367, 1842, 9217, 46092, 230467, 1152342, 5761717, 28808592, 144042967

it is clear that the ninth one is 5761717.

题意:给4e8个unsigned long long范围内整数,求其第l大数为多少?

分析:4e8个数,利用分块算法将其分成N块,块与块之间存在绝对的大小关系,就能间接的快速比较,然后在块内求出第l大。

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
const LL NV=1e14+1;
int num[200010];
LL A,B,s,s0,b[50000];
int n,l,k;
int main()
{
    while(scanf("%llu%llu%d%d%llu",&A,&B,&l,&n,&s)!=EOF)
    {
        for(int i=1;i<=200000;i++)num[i]=0;
        s0=s;
        for(int i=1;i<=n;i++)
        {
            num[s0/NV]++;
            s0=s0*A+B;
        }
        for(int i=0;i<200000;i++)
        {
            if(l>num[i])
                l-=num[i];
            else
            {
                k=i;
                break;
            }
        }
        s0=s;
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(k==s0/NV)
                b[++cnt]=s0;
            s0=s0*A+B;
        }
        sort(b+1,b+cnt+1);
        printf("%I64d\n",b[l]);
    }
    return 0;
}

查看评论

2018湖北省赛网络赛H: GSS and OJ Submissions(分块)

2018湖北省赛网络赛H: GSS and OJ Submissions(分块) 一道神奇的分块题目 之前没怎么见过这种类型的 长见识了...
  • f2935552941
  • f2935552941
  • 2018-04-16 21:06:33
  • 28

今日头条杯2018湖北省大学生程序设计竞赛(网络赛)

A. GSS and CQ time limit per test1 second memory limit per test512 megabytes inputstandard input ...
  • Fire_to_cheat_
  • Fire_to_cheat_
  • 2018-04-17 21:03:45
  • 83

Problem F. A-maze-ing-----“今日头条”杯2018年湖北省赛(网络赛)

“今日头条”杯2018年湖北省赛(网络赛):所有题目链接 可以提交的链接(不知道现在还能进不了,你还要有账号):传送门 Problem F. A-maze-ing 题目大意:很坑啊,当初读了...
  • nhl19961226
  • nhl19961226
  • 2018-04-16 16:23:53
  • 53

今日头条杯 2018 年首届湖北省大学生程序设计竞赛 (网络赛)Problem B.(计算几何)

Problem B. GSS and Interesting SculptureInput file: standard inputOutput file: standard outputTime l...
  • qq_41593380
  • qq_41593380
  • 2018-04-15 20:11:45
  • 177

2018 HBCPC 菜鸡选手记

我果然太菜了 A B——T2 D——T4 C——T3 F 我果然太菜了 作为学校最菜的队员,今天下午被虐惨了。 一下午才做A-D四道题 官方题解链接 晚上吃...
  • yuyilahanbao
  • yuyilahanbao
  • 2018-04-15 18:22:38
  • 5

“今日头条”杯2018年湖北省赛(网络赛)F(tarjan缩点后找有向无环图的最长路)

有向无环图的最长路简单求法搜索博客:点击打开链接题意:给出n个点,m条边,这是一个有向图,然后问你能不能找一个最长路,那么就有一个问题如果途中有环呢,那么我们就得先用tarjan缩点,然后变成了有向无...
  • zezzezzez
  • zezzezzez
  • 2018-04-18 20:58:39
  • 26

2018 蓝桥杯省赛 B 组模拟赛(一)G. 数列求值

对于一个含有 n+2个元素的数列,满足这样的递归公式现在我们知道 和的值。现在请你帮忙计算的值。输入格式第一行输入一个整数 n(1≤n≤1000)。第二行输入两个数 和 ,接着是 n个数据分别是。所有...
  • CS33sun
  • CS33sun
  • 2018-03-09 22:54:48
  • 129

2016国赛真题——网络搭建与应用赛题

  • 2017年12月20日 14:13
  • 380KB
  • 下载

今日头条杯2018湖北省大学生程序设计竞赛(网络赛)The 2018 Hubei Collegiage Programming Contest Online

蒟蒻打的是网络赛,讲道理会比WHU现场的朋友们轻松很多,然而,各种小错误不断,G交互题各种wa,赛后补题才发现自己多了一个scanf, 已被队友锤爆(倒地) 行啦,现在来个伪全题解 PROBLE...
  • Murphyc
  • Murphyc
  • 2018-04-18 19:31:15
  • 86
    个人资料
    持之以恒
    等级:
    访问量: 1万+
    积分: 1029
    排名: 4万+