hdu 5288 OO’s Sequence(two point + rmq)
来源:互联网 发布:linux重启tomcat服务 编辑:程序博客网 时间:2024/06/03 21:47
题目链接:hdu 5288 OO’s Sequence
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 1e4 + 5;const int maxm = 1e5 + 5;const int mod = 1e9 + 7;int N, v[maxm], a[maxm], l[maxm], r[maxm];vector<int> G[maxn];void init () {for (int i = 1; i < maxn; i++) {for (int j = i; j < maxn; j += i)G[j].push_back(i);}}int main () {init();while (scanf("%d", &N) == 1) {memset(v, 0, sizeof(v));memset(l, 0, sizeof(l));for (int i = 1; i <= N; i++) {scanf("%d", &a[i]);for (int j = 0; j < G[a[i]].size(); j++) {l[i] = max(l[i], v[G[a[i]][j]]);}v[a[i]] = i;}int ans = 0;for (int i = 0; i <= N; i++)r[i] = v[i] = N + 1;for (int i = N; i; i--) {for (int j = 0; j < G[a[i]].size(); j++) {r[i] = min(r[i], v[G[a[i]][j]]);}v[a[i]] = i;ans = (ans + (i - l[i]) * (r[i] - i) % mod ) % mod;}printf("%d\n", ans);}return 0;}
0 0
- hdu 5288 OO’s Sequence(two point + rmq)
- hdu 5288 OO’s Sequence(two pointers)
- HDU 5288 OO‘s sequence (技巧)
- HDU 5288 OO’s Sequence(数论)
- hdu 5288OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- HDU 5288 OO’s Sequence(数学啊 多校2015)
- 百练2757最长上升子序列
- IndexError: list index out of range的错误原因
- VS中使用TinyXml操作xml文件
- 计算机网络读书笔记-----网络层
- Activity里添加ViewGroup ViewGroup里添加ViewGroup
- hdu 5288 OO’s Sequence(two point + rmq)
- 渣渣ACM日记——3461-Oulipo(POJ)
- PAT (Advanced Level) 1068. Find More Coins (30) DFS+剪枝 或 动态规划
- hdu 5319 Painter
- Reorder List
- tinyxml使用笔记与总结 http://www.cppblog.com/elva/archive/2008/04/24/47907.html
- 【面试加分项】java异常处理之try_catch_finally
- 使用命令行WScript和vbs创建快捷方式
- interest_points_comparison.hdev不同检测感兴趣点的算法比较 相关例程学习