F. Gabriel's Pocket Money 2017- BUPT Collegiate Programming Contest - sync

时间限制 2000 ms 内存限制 65536 KB

题目描述


For centuries, Heaven has required its young angels to live and study among humans in order to become full-fledged angels. This is no different for top-of-her-class Gabriel White Tenma, who believes it is her mission to be a great angel who will bring happiness to mankind.
However, Gabriel grows addicted to video games on Earth and eventually becomes a hikikomori. What's worse, her grades in school becomes erratic, which directly determines how much pocket money she could get from Heaven. Every week Gabriel needs to report her recent grade in school, and Heaven will give her some money based on her reports. In each report Gabriel is asked to offer two grades, the grade she get this week and a grade she has ever got before this week to show she is improved or at least not going backwards, like "I once got 59 points, and I get 61 points this week. So I'm improved!" or "I once got 59 points, and this week I get 59 points again. So I'm not going backwards!". Then Heaven will give her as much pocket money as her former grade points she reported (In both cases, she can get 59 dollars. What a hardworking angel!). If she can't offer such report, no pocket money would be offered this week. For example, the first week (she has only one grade).
Gabriel knows how to maximize the pocket money she get from heaven. Giving you Gabriel's transcript of this semester in order, can you figure out how much pocket money she can get in total?

输入格式

Input contains multiple test cases.
For each test case:

  • The first line contains an integers n(1≤n≤106), indicating the number of weeks;
  • The second line contains n integers a1,a2,...,an(0≤ai≤106).

输出格式

For each test case, output a number in a single line, indicating the total pocket money Gabriel can get. You should let answer modulo 19260817 before printing it.

输入样例

3
1 2 3
5
3 5 1 2 4

输出样例

3
7
【题意】给你一个数组,然后对于每个数,找到左边小于等于它的最大的那个数,然后依次累加起来。
【分析】数据小的话,可以O(N*N)来做,可是 N<1e6,那就只能树状数组了,对于每一个数,向上lowbit更新Lazy标记,Lazy标记的是
到目前为止这个数左边小于等于它的最大的数,那么查询的时候只需要向下lowbit查询取最大值就行了,复杂度NlogN。
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define met(a,b) memset(a,b,sizeof a)
#define inf 10000000
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int N = 1e6+;
const double eps = 1e-;
int n,sum[N],m,cnt,k;
int lazy[N],a[N];
void update(int x,int num){
for(int i=x;i<N;i+=i&(-i)){
lazy[i]=max(lazy[i],num);
}
}
int query(int x){
int ret=;
for(int i=x;i>=;i-=i&(-i)){
ret=max(ret,lazy[i]);
}
return ret==?ret:ret-;
}
int main() {
int T,x,y,xx,yy;
while(~scanf("%d",&n)){
met(lazy,);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
a[i]++;
}
ll ans=;
for(int i=;i<=n;i++){
int s=query(a[i]);
ans=(ans+s)%;
update(a[i],a[i]);
}
printf("%lld\n",ans);
}
return ;
}

北邮校赛 F. Gabriel's Pocket Money(树状数组)的更多相关文章

  1. AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组

    题目传送门:F - Operations on a Matrix (atcoder.jp) 题意: 给一个N*M大小的零矩阵,以及Q次操作.操作1(l,r,x):对于 [l,r] 区间内的每列都加上x ...

  2. Codeforces 1167 F Scalar Queries 计算贡献+树状数组

    题意 给一个数列\(a\),定义\(f(l,r)\)为\(b_1, b_2, \dots, b_{r - l + 1}\),\(b_i = a_{l - 1 + i}\),将\(b\)排序,\(f(l ...

  3. 北邮校赛 I. Beautiful Array(DP)

    I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...

  4. 北邮校赛 H. Black-white Tree (猜的)

    H. Black-white Tree 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...

  5. 2015 北京网络赛 E Border Length hihoCoder 1231 树状数组 (2015-11-05 09:30)

    #1231 : Border Length 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Garlic-Counting Chicken is a special spe ...

  6. 【洛谷】NOIP提高组模拟赛Day2【动态开节点/树状数组】【双头链表模拟】

    U41571 Agent2 题目背景 炎炎夏日还没有过去,Agent们没有一个想出去外面搞事情的.每当ENLIGHTENED总部组织活动时,人人都说有空,结果到了活动日,却一个接着一个咕咕咕了.只有不 ...

  7. 「模拟赛20180307」三元组 exclaim 枚举+树状数组

    题目描述 给定 \(n,k\) ,求有多少个三元组 \((a,b,c)\) 满足 \(1≤a≤b≤c≤n\)且\(a + b^2 ≡ c^3\ (mod\ k)\). 输入 多组数据,第一行数据组数\ ...

  8. Distance(2019年牛客多校第八场D题+CDQ+树状数组)

    题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...

  9. 【CSP模拟赛】奇怪的队列(树状数组 &二分&贪心)

    题目描述 nodgd的粉丝太多了,每天都会有很多人排队要签名.  今天有n个人排队,每个人的身高都是一个整数,且互不相同.很不巧,nodgd今天去忙别的事情去了,就只好让这些粉丝们明天再来.同时nod ...

随机推荐

  1. [Luogu 2805] NOI2009 植物大战僵尸

    这题是个比较经典的最大权闭合子图,可以建图转化为最小割问题,再根据最大流最小割定理,采用任意一种最大流算法求得. 对于每个点,如果点权w为正,则从源点到这个点连一条边权为w的有向边:否则如果w为负则从 ...

  2. django自带分页代码

    django分页 {% if is_paginated %} <div class="pagination-simple"> <!-- 如果当前页还有上一页,显示 ...

  3. JAVA JDBC(存储过程和事务管理)

    1.什么是存储过程 存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中,经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程 ...

  4. [hdu2460]network(依次连边并询问图中割边数量) tarjan边双联通分量+lca

    题意: 给定一个n个点m条边的无向图,q个操作,每个操作给(x,y)连边并询问此时图中的割边有多少条.(连上的边会一直存在) n<=1e5,m<=2*10^5,q<=1e3,多组数据 ...

  5. 【NOIP】提高组2012 疫情控制

    [题意]n个点的树,1为根,要求删除一些点使得截断根节点和所有叶子结点的路径(不能删根,可以删叶子).有m支军队在m个点上,每时刻所有军队可以走一步,最终走到的地方就是删除的点,求最短时间. [算法] ...

  6. 第八周 yukun 20155335

  7. Kubernetes: 集群网络配置 - flannel

    参考: [ Kubernetes 权威指南 ] Kubernetes 集群搭建可以参考 [ Kubernetes : 多节点 k8s 集群实践 ] 在多个 Node 组成的 Kubernetes 集群 ...

  8. ios的app,有新版本时必须先更新。

    现在没时间整理,先把代码贴出来,以后再做详细的思路整理. 1 在AppController.mm的didFinishLaunchingWithOptions方法里面获取本地应用版本信息,保存起来. / ...

  9. 【洛谷 P3194】 [HNOI2008]水平可见直线 (单调栈)

    题目链接 把线段以斜率为第一关键字,截距为第二关键字升序排序. 然后维护一个单调栈,保证栈中两两线段的交点的\(x\)坐标单调上升就行了.栈中的线段即为所求. #include <cstdio& ...

  10. 工程化管理--maven

    mavne模型 可以看出 maven构件都是由插件支撑的 maven的插件位置在:F:\MavenRepository\org\apache\maven\plugins Maven仓库布局 本地仓库 ...