bzoj 3173

后面插进取的数并不影响前面的结果,所以用splay把最后的序列求出来直接LIS即可

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 1e9
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define NM 100000+5
10 using namespace std;
11 int read(){
12     int x=0,f=1;char ch=getchar();
13     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
14     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
15     return x*f;
16 }
17 int n,_x,_t,a[NM],b[NM],c[NM][2],f[NM],tot,root,d[NM],len;
18 int _d(int x){
19     return c[f[x]][1]==x;
20 }
21 void newnode(int &r,int fa,int k){
22     r=++tot;f[r]=fa;c[r][0]=c[r][1]=0;b[r]=1;
23 }
24 void rot(int x){
25     int y=f[x],kind=!_d(x);
26     c[y][!kind]=c[x][kind];f[c[x][kind]]=y;
27     c[f[y]][_d(y)]=x;f[x]=f[y];
28     c[x][kind]=y;f[y]=x;
29     b[y]=b[c[y][0]]+b[c[y][1]]+1;b[x]=b[c[x][0]]+b[c[x][1]]+1;
30 }
31 void splay(int x,int goal=0){
32     for(int y=f[x];y!=goal;y=f[x]){
33         if(f[y]!=goal)
34         _d(x)==_d(y)?rot(y):rot(x);
35         rot(x);
36     }
37     if(goal==0)root=x;
38 }
39 void ins(int x){
40     int r=root;
41     if(x!=tot+1){
42     while(1)
43     if(b[c[r][0]]>=x)r=c[r][0];
44         else{
45         x-=b[c[r][0]]+1;
46         if(!x)break;
47         r=c[r][1];
48     }
49     if(!c[r][0]){
50         newnode(c[r][0],r,_t);splay(c[r][0]);return;
51     }
52     for(r=c[r][0];c[r][1];)r=c[r][1];
53     }else
54     while(c[r][1])r=c[r][1];
55     newnode(c[r][1],r,_t);
56     splay(c[r][1]);
57 }
58 void out(int r){
59     if(c[r][0])out(c[r][0]);
60     a[++n]=r;
61     if(c[r][1])out(c[r][1]);
62 }
63 int main(){
64 //    freopen("data.in","r",stdin);
65     n=read()-1;
66     read();newnode(root,0,_t=1);
67     while(n--){
68         ++_t;_x=read()+1;
69         ins(_x);
70     }
71     n++;
72     out(root);
73 //    inc(i,1,n)printf("%d ",a[i]);
74 //    printf("\n");
75     d[len=1]=a[1];
76     inc(i,2,n)
77     if(d[len]>=a[i])d[lower_bound(d,d+len+1,a[i])-d]=a[i];
78     else d[++len]=a[i];
79     mem(b);_t=0;
80     inc(i,1,len)b[d[i]]=i;
81     inc(i,1,n){
82         _t=max(b[i],_t);
83         printf("%d\n",_t);
84     }
85     return 0;
86 }
View Code

 

转载于:https://www.cnblogs.com/onlyRP/p/5111254.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BZOJ 2908 题目是一个数据下载任务。这个任务要求下载指定的数据文件,并统计文件中小于等于给定整数的数字个数。 为了完成这个任务,首先需要选择一个合适的网址来下载文件。我们可以使用一个网络爬虫库,如Python中的Requests库,来帮助我们完成文件下载的操作。 首先,我们需要使用Requests库中的get()方法来访问目标网址,并将目标文件下载到我们的本地计算机中。可以使用以下代码实现文件下载: ```python import requests url = '目标文件的网址' response = requests.get(url) with open('本地保存文件的路径', 'wb') as file: file.write(response.content) ``` 下载完成后,我们可以使用Python内置的open()函数打开已下载的文件,并按行读取文件内容。可以使用以下代码实现文件内容读取: ```python count = 0 with open('本地保存文件的路径', 'r') as file: for line in file: # 在这里实现对每一行数据的判断 # 如果小于等于给定整数,count 加 1 # 否则,不进行任何操作 ``` 在每一行的处理过程中,我们可以使用split()方法将一行数据分割成多个字符串,并使用int()函数将其转换为整数。然后,我们可以将该整数与给定整数进行比较,以判断是否小于等于给定整数。 最后,我们可以将统计结果打印出来,以满足题目的要求。 综上所述,以上是关于解决 BZOJ 2908 数据下载任务的简要步骤和代码实现。 希望对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值