HDU 2227 Find the nondecreasing subsequences (数状数组)
Find the nondecreasing subsequences
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1072 Accepted Submission(s): 370
1 2 3
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; const int mod=;
const int N=; struct node{
int val,id;
}a[N]; int n,b[N],c[N],arr[N]; int lowbit(int x){
return x&(-x);
} void update(int i,int val){
while(i<=n){
arr[i]+=val;
arr[i]%=mod;
i+=lowbit(i);
}
} int Sum(int i){
int ans=;
while(i>){
ans+=arr[i];
ans%=mod;
i-=lowbit(i);
}
return ans;
} int cmp(node a,node b){
return a.val<b.val;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n)){
memset(b,,sizeof(b));
memset(arr,,sizeof(arr));
for(int i=;i<=n;i++){
scanf("%d",&a[i].val);
a[i].id=i;
}
sort(a+,a+n+,cmp);
b[a[].id]=;
for(int i=;i<=n;i++)
if(a[i].val==a[i-].val)
b[a[i].id]=b[a[i-].id];
else
b[a[i].id]=i;
for(int i=;i<=n;i++){
c[i]=Sum(b[i]);
update(b[i],c[i]+);
}
printf("%d\n",Sum(n));
}
return ;
}
HDU 2227 Find the nondecreasing subsequences (数状数组)的更多相关文章
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- HDU 2227 Find the nondecreasing subsequences dp思想 + 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=2227 用dp[i]表示以第i个数为结尾的nondecreasing串有多少个. 那么对于每个a[i] 要去找 & ...
- HDU 2227 Find the nondecreasing subsequences (线段树)
Find the nondecreasing subsequences Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/3 ...
- HDU 2227 Find the nondecreasing subsequences(DP)
Problem Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3 ...
- HDU 2227 Find the nondecreasing subsequences
题目大意:给定一个序列,求出其所有的上升子序列. 题解:一开始我以为是动态规划,后来发现离散后树状数组很好做,首先,c保存的是第i位上升子系列有几个,那么树状数组的sum就直接是现在的答案了,不过更新 ...
- hdu 1556 A - Color the ball 数状数组做法
#include<bits/stdc++.h> using namespace std; ; int n; int c[maxn]; int lowbit(int x) { return ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1166 敌兵布阵 (数状数组,或线段树)
题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...
- hdu 5869 区间不同GCD个数(树状数组)
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
随机推荐
- 用Hadoop构建电影推荐系统
转自:http://blog.fens.me/hadoop-mapreduce-recommend/ Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, ...
- linux下性能分析命令[总结]
1.前言 在linux下开发程序,为了追求高性能,经常需要测试程序的性能,包括cpu.内存.io.网络等等使用情况.liunx下提供了众多命令方便查看各种资源的使用情况.经常用的有ps.top.fre ...
- 前端开发必备 40款优秀CSS代码编写工具推荐
摘要:CSS工具可以简化工作流,可以提高CSS编写速度,是开发者和设计者所不可缺少的.本文列举了40种CSS工具,功能涉及CSS菜单.动画.3D图形.响应式页面.图层.按钮等界面元素的设计与制作,你定 ...
- java 上传图片压缩图片
package com.bitspace.flame.util; import java.io.File; import java.awt.Image;import java.awt.image.Bu ...
- OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so
OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so ...
- 【Python】使用geopy由地址找经纬度等信息
代码: from geopy.geocoders import Nominatim geolocator = Nominatim() location = geolocator.geocode(&qu ...
- mysql 分区说明
当 MySQL的总记录数超过了100万后,性能会大幅下降,可以采用分区方案 分区允许根据指定的规则,跨文件系统分配单个表的多个部分.表的不同部分在不同的位置被存储为单独的表. 1.先看下innodb的 ...
- 生日日期联动选择birthday.js
实例下载
- jQuery 超屏加载
jQuery 超屏加载,当文档超出屏幕的高度时,加载最新下个列数据 $(window).scroll(function () { var height = $(document).height(); ...
- 使用devenv/MSBuild在命令行编译sln或csproj
一 使用devenv来build单个project devenv是VisualStudio的可执行程序,一般安装在“C:\Program Files (x86)\Microsoft Visual ...