4725: [POI2017]Reprezentacje ró?nicowe

4725: [POI2017]Reprezentacje ró?nicowe

Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 99 Solved: 48
[Submit][Status][Discuss]
Description

给定一个数列a:
当n<=2时,a[n]=n
当n>2,且n是奇数时,a[n]=2a[n-1]
当n>2,且n是偶数时,a[n]=a[n-1]+r[n-1]
其中r[n-1]=mex(|a[i]-a[j]|)(1<=i<=j<=n-1),mex{S}表示最小的不在S集合里面的非负整数。
数列a的前若干项依次为:1,2,4,8,16,21,42,51,102,112,224,235,470,486,972,990,1980。
可以证明,对于任意正整数x,只存在唯一一对整数(p,q)满足x=a[p]-a[q],定义为repr(x)。
比如repr(17)=(6,3),repr(18)=(16,15)。
现有n个询问,每次给定一个正整数x,请求出repr(x)。
Input

第一行包含一个正整数n(1<=n<=10^5)。
接下来n行,每行一个正整数x(1<=x<=10^9),表示一个询问。
Output

输出n行,每行两个正整数p,q,依次回答每个询问。
Sample Input

2

17

18
Sample Output

6 3

16 15
HINT

Source

鸣谢Claris上传

注意到奇数位置的生成公式
于是每隔两个位置就会扩大两倍
那么当算出大概前 log2109 f 时,最后面的那个数减前面的数的差值就很大了
显然这些对我们的查询没有贡献
因此只需要暴力算出前面一些位置的f
后面全部可以随便搞搞求出来

#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;

const int N = 233;
const int maxn = 1E5 + 10;
const int Max = 1000000000;
typedef long long LL;

int tp,stk[maxn];
LL f[N];

map <int,pair<int,int> > M;

inline int getint()
{
    char ch = getchar(); int ret = 0;
    while (ch < '0' || '9' < ch) ch = getchar();
    while ('0' <= ch && ch <= '9')
        ret = ret * 10 + ch - '0',ch = getchar();
    return ret;
}

int main()
{
    #ifdef DMC
        freopen("DMC.txt","r",stdin);
    #endif

    f[1] = 1; f[2] = 2;
    stk[tp = 1] = 1; M[1] = make_pair(2,1);
    for (int i = 3; i <= 70; i++)
    {
        if (!(i & 1))
        {
            LL now;
            for (int k = 1; ; k++)
                if (!M.count(k)) {now = k; break;}
            f[i] = f[i - 1] + now;
        }
        else f[i] = f[i - 1] + f[i - 1];
        for (int j = 1; j < i; j++)
            if (f[i] - f[j] <= Max)
            {
                stk[++tp] = f[i] - f[j];
                M[f[i] - f[j]] = make_pair(i,j);
            }
    }
    sort(stk + 1,stk + tp + 1); int n = getint();
    while (n--)
    {
        int x = getint(); pair <int,int> now;
        int pos = lower_bound(stk + 1,stk + tp + 1,x) - stk;
        if (stk[pos] == x) now = M[stk[pos]];
        else
        {
            now.first = 70 + (x - pos + 1) * 2;
            now.second = now.first - 1;
        }
        printf("%d %d\n",now.first,now.second);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值