• BZOJ4725: [POI2017]Reprezentacje ró?nicowe


    $n leq 1e5$,$x leq 1e9$。

    1e9呵呵,暴力处理$a_n$的前几项直到1e9。然后处理出差的数列,每次在这里面找,找得到就回答,找不到,那有贡献的只有$a_i-a_{i-1},a_i>1e9$,并且是越来越大的,那在原有的里面二分一下看要补几个即可。

    注意$Max=1e9+多一点$,否则会少算$a_{56}-a_{54}$等!

     1 #include<stdio.h>
     2 #include<string.h>
     3 //#include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 #define LL long long
     8 int qread()
     9 {
    10     char c; int s=0,t=1; while ((c=getchar())<'0' || c>'9') (c=='-') && (t=-1);
    11     do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*t;
    12 }
    13 
    14 //
    15 
    16 int tot;
    17 #define maxn 233333
    18 int a[maxn];
    19 struct Node
    20 {
    21     int x,y,v;
    22     bool operator < (const Node &b) const {return v<b.v;}
    23 }b[maxn]; int lb;
    24 
    25 int main()
    26 {
    27     int Max=1100000000,n=2;
    28     a[1]=1; a[2]=2;
    29     b[++lb]=(Node){2,1,1};
    30     for (n=3;;n++)
    31     {
    32         if (n&1) a[n]=a[n-1]<<1; else
    33         {
    34             for (int k=2;k<=lb;k++) if (b[k].v!=b[k-1].v+1) {a[n]=b[k-1].v+1; break;}
    35             if (!a[n]) a[n]=b[lb].v+1;
    36             a[n]+=a[n-1];
    37         }
    38         for (int i=1;i<n;i++) b[++lb]=(Node){n,i,a[n]-a[i]};
    39         sort(b+1,b+1+lb);
    40         if (a[n]>Max) break;
    41     }
    42     int m=qread();
    43     while (m--)
    44     {
    45         int x=qread(),y;
    46         if (b[y=lower_bound(b+1,b+1+lb,(Node){0,0,x})-b].v==x) printf("%d %d
    ",b[y].x,b[y].y);
    47         else
    48         {
    49             int p=x-(y-1);
    50             printf("%d %d
    ",n+p*2-1,n+p*2-2);
    51         }
    52     }
    53     return 0;
    54 }
    View Code
  • 相关阅读:
    nanoPI kernel compile record
    Golang go get第三方库的坑
    Python解析Linux命令行
    Linux:dd命令
    Golang异常处理
    Golang自定义包导入
    Golang覆盖写入文件的小坑
    Golang数据类型总结及其转换
    ASP.NET学习之页面传值(8)_Application传值
    ASP.NET学习之页面传值(7)_Cookie传值
  • 原文地址:https://www.cnblogs.com/Blue233333/p/9085337.html
Copyright © 2020-2023  润新知