二分寻找对于指定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. O-C相关-08-动态类型与静态类型

    08-动态类型与静态类型 1, 什么是动态类型和静态类型 1) 动态语言 又叫动态编程语言,是指程序在运行时可以改变其结构:新的函数可以被引进,已有的函数可以被删除等在结构上的变化.比如众所周知的EC ...

  2. Windows下管理Python安装包

    Pip:A tool for installing and managing Python packages. Pip在Python环境中的地方就相当于Ubuntu环境中的apt-get.以及Mac系 ...

  3. groovy --不注意的小错误(java.lang.String.positive() is applicable)

    sql 语句拼接报错: No signature of method: java.lang.String.positive() is applicable for argument types: () ...

  4. 【ADO.NET】8、DataSet的使用

    一.DataSet的查询 SqlDataReader 适用于大型数据的读取,它是一条一条的读取,读取出来的数据是存放在服务器上当正在读取数据的时候,突然与服务中断,将无法读取后面的数据DataSet ...

  5. scala - 从合并两个Map说开去 - foldLeft 和 foldRight 还有模式匹配

    开发中遇到需求:合并两个Map集合对象(将两个对应KEY的值累加) 先说解决方案: ( map1 )) ) } 这特么什么鬼  (╯‵□′)╯""┻━┻☆))>○<)  ...

  6. 关于web开发的一点理解

    对于web开发上的一点理解 1 宏观上的一点理解 网页从请求第地址 到获得页面的过程:从客户端(浏览器)通过地址 从soket把请求报文封装发往服务端   服务端通过解析报文并处理报文最后把处理的结果 ...

  7. You have new mail in /var/spool/mail/root 烦不烦你(转)

    转自(http://blog.csdn.net/yx_l128125/article/details/7425182) 有时在进入系统的时候经常提示You have new mail in /var/ ...

  8. mysql 查找包含特定名字的表

    SELECT distinct TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '%medias%'

  9. android studio 自动序列化类插件

    https://github.com/mcharmas/android-parcelable-intellij-plugin

  10. 关于C# Winform 程序开机自动启动

    1.程序运行时调用下面方法即可. /// <summary> /// 设置开机自动启用 /// </summary> private void SetAutoStart() { ...