CodeForces 315E - Sereja and Subsequences 阅读理解+树状数组
来源:互联网 发布:搜狗 mac 设置 编辑:程序博客网 时间:2024/05/21 03:56
题目好久才看懂.....意思是在将这串所有非降子串值相加...子串值的定义是这串中所有元素相乘.
ai最大为10^6...用一个10^6大的树状数组来维护(线段树也可以..不过空间和时间都会差一些)...从左扫到右...插入查找更新答案...
值得注意的是元素相等的情况..如样例二
1 2 2 -> (1 , 2 , 12 , 22 , 122)=13
可见元素相同时不需要重复计算....所以每次在更新答案时..减去这个元素前上次更新的值...
Program:
#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>#include<queue>#include<stack>#include<set>#include<algorithm>#define ll long long#define oo 1000000007#define pi acos(-1.0)#define MAXN 10000005using namespace std; ll S[MAXN],Pre[MAXN];ll getsum(int k){ ll sum=0; while (k) { sum=(sum+S[k])%oo; k-=k&(-k); } return sum;}void update(int k,ll x) { while (k<=MAXN) { S[k]=(S[k]+x)%oo; k+=k&(-k); } return;}int main(){ int i,n; ll ans; freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); while (~scanf("%d",&n)) { memset(S,0,sizeof(S)); memset(Pre,0,sizeof(Pre)); ans=0; for (i=1;i<=n;i++) { ll x,t; scanf("%I64d",&x); t=(getsum(x)*x+x)%oo; ans=(ans+t-Pre[x])%oo; update(x,t-Pre[x]); Pre[x]=t; } if (ans<0) ans+=oo; printf("%I64d\n",ans); } return 0;}
- CodeForces 315E - Sereja and Subsequences 阅读理解+树状数组
- Codeforces 315E Sereja and Subsequences【思维+Dp】
- CF - 314C - Sereja and Subsequences(树状数组+dp)
- Codeforces 314C. Sereja and Subsequences
- Codeforces Round 223 380C Sereja and Brackets 树状数组
- codeforces 368B B. Sereja and Suffixes(树状数组)
- CF 315B - Sereja and Array(树状数组)
- CodeForces 425E Sereja and Sets
- Codeforces 367E Sereja and Intervals DP
- Codeforces 314E Sereja and Squares
- Codeforces 597C Subsequences dp + 树状数组
- codeforces-597C-Subsequences【树状数组】
- Subsequences CodeForces - 597C 树状数组 + dp
- Codeforces 387E George and Cards(二分+树状数组)
- George and Cards - CodeForces 387E 树状数组
- CodeForces - 369E Valera and Queries 离线+树状数组
- Codeforces 369E Valera and Queries --树状数组+离线操作
- CodeForces - 369E Valera and Queries(树状数组)
- 动态代理的工作原理图
- C语言中的文字常量区
- python学习笔记(二):递归函数
- ant运行findbugs出错:java.lang.NoClassDefFoundError: org/apache/commons/lang/StringEscapeUtils
- 解决“adb.exe已停止工作”的办法
- CodeForces 315E - Sereja and Subsequences 阅读理解+树状数组
- IE诡异bug记录
- 遇到的check the manual that corresponds to your MySQL server version for the right syntax错误
- confirm的使用详解
- 1050 To the Max DP
- POJ 1690 (Your)((Term)((Project))) 水题
- AVAudioPlayer的使用
- java.lang.NoClassDefFoundError: javax.annotation.meta.When.class
- ajax实现点击弹出选择列表