HDU - 3450 Counting Sequences
来源:互联网 发布:js select改变事件 编辑:程序博客网 时间:2024/05/21 14:58
题意:求个数大于等于2的序列,要求每相邻的两个的大于d,求满足的个数
思路:同样是树状数组的应用,跟前面两题类似,求每次加入的a[i],先求范围在[a[i]-d,a[i]+d]的个数,再加到a[i]上,加一加的是本身,还有要注意的是,要减去1个的情况,跟前面两题不一样,
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 100005;const int MOD = 9901;int n,arr[MAXN],k;int brr[MAXN],cnt,f[MAXN];int crr[MAXN];int lowbit(int x){return x&(-x);}void update(int x,int d){while (x < MAXN){crr[x] = (crr[x]+d) % MOD;x += lowbit(x);}}int sum(int x){int ans = 0;while (x > 0){ans = (ans + crr[x])%MOD;x -= lowbit(x);}return ans;}int main(){while (scanf("%d%d",&n,&k) != EOF){cnt = 1;memset(crr,0,sizeof(crr));for (int i = 0; i < n; i++){scanf("%d",&arr[i]);brr[i] = arr[i];}sort(brr,brr+n);f[0] = brr[0];for (int i = 1; i < n; i++)if (brr[i] != brr[i-1])f[cnt++] = brr[i];f[cnt++] = INF;for (int i = 0; i < n; i++){int x = lower_bound(f,f+cnt,arr[i]) - f + 1;int y = upper_bound(f,f+cnt,arr[i]+k) - f;int z = lower_bound(f,f+cnt,arr[i]-k) - f + 1;int val = sum(y) - sum(z-1) + 1;val = (val%MOD+MOD) % MOD;update(x,val);}int ans = sum(cnt);ans = ((ans-n)%MOD+MOD)%MOD;cout << ans << endl;}return 0;}
0 0
- HDU 3450 Counting Sequences
- hdu 3450 Counting Sequences
- hdu 3450 Counting Sequences
- HDU - 3450 Counting Sequences
- HDU 3450 Counting Sequences
- hdu 3450 Counting Sequences(树状数组)
- HDU 3450 Counting Sequences 树状数组
- HDU 3450 Counting Sequences (树状数组)
- hdu 3450 Counting Sequences 树状数组
- hdu 3450 Counting Sequences 线段树
- HDU 3450 Counting Sequences(线段树)
- HDU 3450 Counting Sequences(树状数组+DP+离散化)
- hdu 3450 Counting Sequences 递推+树状数组
- hdu 3450 Counting Sequences(树状数组+排序离散化)
- HDU 3450 Counting Sequences(DP + 树状数组)
- Counting Sequences
- HDU3450 Counting Sequences
- [TOJ 3541] Counting Sequences
- 学习笔记_web——表单验证
- 排序之快速排序
- 使用myeclipse搭建struts2环境
- 10 个 lsof 命令行的使用示例
- 【LeetCode】Decode Ways
- HDU - 3450 Counting Sequences
- 关于 win8.1 激活问题
- Android WebView自定义处理错误页面显示(404等)
- NGUI 基础 -- 功能组件
- 网络负载均衡
- 学习笔记_oracle——安装
- boost::asio学习之[四]udp client server 异步server
- 2014 编程之美 资格赛 第一题 同构
- 过滤器、监听器、拦截器的区别