分析:这种题烂大街,n^2,然后数据结构优化下到nlogn,离散化

#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const int mod=;
int p[N],n,a[N],c[N];
int cnt;
void add(int x,int t){
for(int i=x;i<=cnt;i+=i&(-i))
c[i]=(c[i]+t)%mod;
}
int ask(int x){
if(x==)return ;
int ans=;
for(int i=x;i>;i-=i&(-i))
ans=(ans+c[i])%mod;
return ans;
}
int main(){
while(~scanf("%d",&n)){
for(int i=;i<=n;++i)
scanf("%d",&a[i]),p[i]=a[i];
sort(p+,p++n);
cnt=unique(p+,p++n)-p-;
memset(c,,sizeof(c));
int ans=;
for(int i=;i<=n;++i){
int pos=lower_bound(p+,p++cnt,a[i])-p;
int tmp=(ask(pos-)+)%mod;
add(pos,tmp);
ans=(ans+tmp)%mod;
}
printf("%d\n",ans);
}
return ;
}

FZU2236 第十四个目标 dp+树状数组优化的更多相关文章

  1. 第十四个目标(dp + 树状数组 + 线段树)

    Problem 2236 第十四个目标 Accept: 17    Submit: 35 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  2. Codeforces 909 C. Python Indentation (DP+树状数组优化)

    题目链接:Python Indentation 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现.现在有一种简化版的Python,只有两种语句: (1)'s'语句:Simple ...

  3. 2015南阳CCPC C - The Battle of Chibi DP树状数组优化

    C - The Battle of Chibi Description Cao Cao made up a big army and was going to invade the whole Sou ...

  4. 【eJOI2020】考试(dp & 树状数组优化)

    Description \(n\) 个正整数排成一列,每个位置 \(i\) 有一个初始值 \(A_i\) 以及目标值 \(B_i\). 一次操作可以选定一个区间 \([l, r]\),并将区间内所有数 ...

  5. bzoj 3594: [Scoi2014]方伯伯的玉米田 dp树状数组优化

    3594: [Scoi2014]方伯伯的玉米田 Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 314  Solved: 132[Submit][Sta ...

  6. Codeforces 909C Python Indentation:树状数组优化dp

    题目链接:http://codeforces.com/contest/909/problem/C 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现. 现在有一种简化版的Pytho ...

  7. BZOJ3594: [Scoi2014]方伯伯的玉米田【二维树状数组优化DP】

    Description 方伯伯在自己的农田边散步,他突然发现田里的一排玉米非常的不美. 这排玉米一共有N株,它们的高度参差不齐. 方伯伯认为单调不下降序列很美,所以他决定先把一些玉米拔高,再把破坏美感 ...

  8. HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)

    题目链接  2017 CCPC Harbin Problem K 题意  给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_ ...

  9. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

随机推荐

  1. svn执行clean up 操作时报错 "Previous operation has not finished; run 'cleanup' if it was interrupted"解决如下!

    今天在项目中更新的时候,突然间爆了一个svn的这个错误,当时提示我去clean up操作,结果我执行clean up操作时候,还是报错,后来坚持出来,是因为ios项目中的一个图标出了问题,使svn进入 ...

  2. SQL索引问题

    很多文章都提到使用IN,OR会破坏索引,造成全表扫描,但实际测试却不是这样. ) 或者 ,) 以上SQL文,第一组(=,IN),第二组(=,OR,IN),每一组的两个SQL文都使用相同的执行计划,执行 ...

  3. 为什么a标签中使用img后的高度多了几个像素?

    a元素下有一个匿名文本,这个文本外有一个匿名行级盒子,它有的默认vertical-align是baseline的,而且往往因为上文line-height的影响,使它有个line-height,从而使其 ...

  4. centos 挂载与卸载硬盘

    fdisk -l //先查询未挂载的硬盘名如:sdb1 等 mkfs.ext3 /dev/xvdb 开始格式化 df -h mount /dev/xvdb /home 开始挂载 vi /etc/fst ...

  5. jquery 里面的$(document).ready 和 DOMContentLoaded

    DOMContentLoaded 事件是当页面的初始dom tree加载好了就会执行. 而不会去等待外部的css 渲染完成和 js执行完成,即下图中的DOM Tree阶段 DOMContentLoad ...

  6. platform_driver_register()--如何match之后调用probe

    int platform_driver_register(struct platform_driver *drv) { drv->driver.bus = &platform_bus_t ...

  7. python实用函数

    dir([obj]) 显示对象属性, 无参数显示全局变量的名字 help([obj]) 显示对象的文档字符串 int(obj) 将一个对象转换为整数 len(obj) 返回对象的长度 range([[ ...

  8. hive--UDF、UDAF

    1.UDF package com.example.hive.udf; import org.apache.hadoop.hive.ql.exec.UDF; import org.apache.had ...

  9. MVC-登录并设置角色

    1.新建一个类,设置角色: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  10. Mac操作系统常用快捷键

    复制:cmd+c      粘贴:cmd+v      剪切:先cmd+c,再cmd+opt+v 显示桌面:cmd+F3      切换输入法:cmd+space 打开Spotlight:ctrl+s ...