BZOJ2093: [Poi2010]Frog

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2093

题解:Orz这题好神!

首先求一位数轴上距离每个点第k近的点。

神做法:维护一个l,r表示a[l--r]是距离i最近的k个点,当i++时,只有可能l++,r++或不改变!!!

然后比较两端距离大小就是第k大!!主要运用了待查询点往右移动时距离他最近的k个元素组成一个区间并且左右端点都单调不减!!!

然后是倍增m,我以为处理处f[i][j]表示i走2^j步之后在哪里,每个倍增一次就好了。没想到卡空间!!!

于是又orz了claris:

while(m)
    {
        if(m&1)
        {
            for1(i,n)t[i]=f[g[i]];
            for1(i,n)g[i]=t[i];
        }
        m>>=1;
        for1(i,n)t[i]=f[f[i]];
        for1(i,n)f[i]=t[i];
    }

跪烂!!!!

代码:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 1000000+5
14 #define maxm 100000+5
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
23 #define mod 1000000007
24 using namespace std;
25 inline ll read()
26 {
27     ll x=0,f=1;char ch=getchar();
28     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
29     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
30     return x*f;
31 }
32 int n,k,f[maxn],g[maxn],t[maxn];
33 ll m,a[maxn];
34 int main()
35 {
36     freopen("input.txt","r",stdin);
37     freopen("output.txt","w",stdout);
38     n=read();k=read();m=read();
39     for1(i,n)a[i]=read();
40     int l=1,r=k+1;f[1]=k+1;
41     for2(i,2,n)
42     {
43         while(r<n&&a[r+1]-a[i]<a[i]-a[l])l++,r++;
44         f[i]=a[r]-a[i]>a[i]-a[l]?r:l;
45     }
46     for1(i,n)g[i]=i;
47     while(m)
48     {
49         if(m&1)
50         {
51             for1(i,n)t[i]=f[g[i]];
52             for1(i,n)g[i]=t[i];
53         }
54         m>>=1;
55         for1(i,n)t[i]=f[f[i]];
56         for1(i,n)f[i]=t[i];
57     }
58     for1(i,n)printf("%d%c",g[i],i==n?‘\n‘:‘ ‘);
59     return 0;
60 }

时间: 2024-10-06 08:23:17

BZOJ2093: [Poi2010]Frog的相关文章

BZOJ 2093: [Poi2010]Frog

Description 从一个点到达与他距离第 \(k\) 小的点,问从每个点跳 \(m\) 次到达那个点. Sol 队列+倍增. 保持队列里的元素个数为 \(k\) ,从前往后扫不难发现左右端点都是单调的. 求跳 \(m\) 次就是倍增了,滚一下数组. Code /************************************************************** Problem: 2093 User: BeiYu Language: C++ Result: Accep

bzoj-2093 Frog

题意: 数轴上有n个点,有一个青蛙在这些点上跳: 规则是每次向距当前点第k小的点跳,如果有相同距离则向下标较小的跳: 求从每个点出发跳了m次后在哪里: 1<=k<n<=1000000,m<=10^18,1<=坐标<=10^18: 题解: 我真是不知道这题出long long 的意义是啥.. 数据范围比较极限,略卡,加点读入优化啥的卡常数才过: 不过Poi上还是挺良心的,除了偶尔乱入的波兰文以外: 这题后半部分显然就是置换的快速幂: 主要问题是前面如何求出一次的置换: 对

HDU 3455 Leap Frog(线性DP)

Problem Description Jack and Jill play a game called "Leap Frog" in which they alternate turns jumping over each other. Both Jack and Jill can jump a maximum horizontal distance of 10 units in any single jump. You are given a list of valid posit

单调队列 BZOJ 2096 [Poi2010]Pilots

2096: [Poi2010]Pilots Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 819  Solved: 418[Submit][Status][Discuss] Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是不行的,于是他找到了你. Input 输入:第一行两个有空格隔开的整数k(0

BZOJ 2086: [Poi2010]Blocks

2086: [Poi2010]Blocks Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 494  Solved: 222[Submit][Status][Discuss] Description 给出N个正整数a[1..N],再给出一个正整数k,现在可以进行如下操作:每次选择一个大于k的正整数a[i],将a[i]减去1,选择a[i-1]或a[i+1]中的一个加上1.经过一定次数的操作后,问最大能够选出多长的一个连续子序列,使得这个子序列的每个数

BZOJ 2080: [Poi2010]Railway 双栈排序

2080: [Poi2010]Railway Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 140  Solved: 35[Submit][Status][Discuss] Description 一个铁路包含两个侧线1和2,右边由A进入,左边由B出去(看下面的图片) 有n个车厢在通道A上,编号为1到n,它们被安排按照要求的顺序(a1,a2,a3,a4....an)进入侧线,进去还要出来,它们要按照编号顺序(1,2,3,4,5....n)从通道B

Frog Jump

A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water. Given a list of stones' positions (in units) in sorted ascending ord

HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 312    Accepted Submission(s): 219 Problem Description One day, you, a clever boy, feel bored in your math class, and then fall

HDU-5578 Friendship of Frog

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1134    Accepted Submission(s): 723 Problem Description N frogs from different countries are standing in a line. Each country is represented by a