二分寻找对于指定pos的最左因数点和最右因数点。

 /* 5288 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int mod = 1e9+;
const int maxn = 1e5+;
const int maxm = ;
vi vc[maxm];
vi fac[maxm];
int a[maxn]; void init() {
int i, j, k; for (i=; i<maxm; ++i) {
for (j=; j*j<=i; ++j) {
if (i%j == ) {
fac[i].pb(j);
k = i / j;
if (k != j)
fac[i].pb(k);
}
}
}
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int n;
int l, r, tmp;
vi::iterator iter;
__int64 ans; init();
while (scanf("%d", &n) != EOF) {
rep(i, , n+) {
scanf("%d", &a[i]);
vc[a[i]].pb(i);
} int sz;
ans = ; rep(i, , n+) {
l = ;
r = n+;
sz = SZ(fac[a[i]]);
rep(j, , sz) {
tmp = fac[a[i]][j];
iter = upper_bound(all(vc[tmp]), i);
if (iter != vc[tmp].end()) {
r = min(r, *iter);
}
if (iter!=vc[tmp].begin()) {
--iter;
if (*iter != i)
l = max(l, *iter);
else if (iter != vc[tmp].begin()) {
--iter;
l = max(l, *iter);
}
}
}
#ifndef ONLINE_JUDGE
tmp = (r-i) * (i-l);
// printf("%d: l = %d, r = %d, c = %d\n", i, l, r, tmp);
#endif
ans = (ans + 1LL * (r-i) * (i-l) % mod) % mod;
} printf("%I64d\n", ans); rep(i, , maxm)
vc[i].clear();
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】5288 OO’s Sequence的更多相关文章

  1. 【HDOJ】5063 Operation the Sequence

    #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...

  2. 【HDOJ】5057 Argestes and Sequence

    树状数组,其实很简单.只是MLE. #include <iostream> #include <cstdio> #include <cstring> using n ...

  3. 思维题 HDOJ 5288 OO’s Sequence

    题目传送门 /* 定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置, 第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i] ...

  4. 【BZOJ1345】[Baltic2007]序列问题Sequence 贪心+单调栈

    [BZOJ1345][Baltic2007]序列问题Sequence Description 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和a ...

  5. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

  6. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. HDOJ 5288 OO’s Sequence 水

    预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 13 ...

  8. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  9. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

随机推荐

  1. unity3d最新面试题与参考答案汇总

    1.在类的构造函数前加上static会报什么错?为什么? 构造函数格式为 public+类名,如果加上static会报错(静态构造函数不能有访问修饰符)原因:静态构造函数不允许访问修饰符,也不接受任何 ...

  2. 20160314 Servlet 入门

    一.Servlet 1.sun提供的一种动态web资源开发技术.本质上就是一段java小程序.可以将Servlet加入到Servlet容器中运行. *Servlet容器 -- 能够运行Servlet的 ...

  3. Dynamic Programming: From novice to advanced

    作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...

  4. DataReader 和 DataSet 的区别

    摘自:http://www.cnblogs.com/zhjjNo1/archive/2009/08/26/1554420.html 第一种解释 DataReader和DataSet最大的区别在于,Da ...

  5. .net闭包的应用

    这里体现出闭包的数据共享 , , , , , , , , , }; ; ; values.ToList().ForEach(s => result1 += s); values.ToList() ...

  6. jQuery选择器(适合初学者哟....)

    选择器是jQuery最基础的东西,本文中列举的选择器基本上囊括了所有的jQuery选择器,也许各位通过这篇文章能够加深对jQuery选择器的理解,它们本身用法就非常简单,我更希望的是它能够提升个人编写 ...

  7. sudo: unable to resolve host XXX 解决方法

    执行sudo命令时候,总是提示sudo: unable to resolve host xxx 解决方法: 法1. 在/etc/hosts/添加hosts映射, 如127.0.0.1 xxx 法2. ...

  8. centos下redis安装

    下载redis http://www.redis.cn/download.html 下载php的redis扩展 https://github.com/phpredis/phpredis#install ...

  9. 13个小技巧帮你征服Xcode

    本文由CocoaChina翻译组成员唧唧歪歪(博客)翻译自David McGraw的博客原文:13 Xcode Tips That Will Help You Conquer Xcode当谈论到iOS ...

  10. E8.ITSM IT运维服务管理系统

      一.     IT运维面临问题 随着企业信息化项目若干年以来的建设积累,IT资产日趋庞大,以及内外部监管部门对IT运维的要求也越来越严格规范,业务部门对企业的IT运维管理也提出了更高的要求. IT ...