二分寻找对于指定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. Extjs combobox设置默认值

    转载:http://www.54mask.com/extjs-combobox-default-value.html 相信很多人都遇到了在ExtJS框架中设置combo组件默认值的需求,ExtJS框架 ...

  2. UpdateProgress使用

    UpdateProgress是一个进度显示条,加在AJAX里能显得更加的人性化(个人认为).现在我们就开始吧: 第一.新建一个AJAX项目.在页面上加上ScriptManager,UpdatePane ...

  3. MD5Untils加密工具类

    package com.dzq.utils; import java.math.BigInteger; import java.security.MessageDigest; import java. ...

  4. 转载-优秀程序员的十个tips

    理解技术债务 技术债务就像信用卡一样,会有很高的利息,时间越长,修复所化的代价就越大.团队应该培养一种保证设计质量的文化,鼓励重构.同时应当鼓励其它有关代码质量的实践. 保持对原理的好奇心 做Andr ...

  5. iOS 图片按比例压缩,指定大小压缩

    使用系统方法UIImageJPEGRepresentation(UIimage *image,CGFloat quality)进行图片质量压缩,暂且叫参数quality为压缩比吧,取值范围为0-1. ...

  6. PAT_1016 部分A+B

    问题描述: 正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6. 现给定A.DA.B ...

  7. ASP.NET获取服务器文件的物理路径

    如下: string fullpath = context.Server.MapPath("hello.htm"); //得到hello.htm的全路径 string conten ...

  8. less学习-语法(二)

    变量 @color1:#fff; 选择器  // Variables @mySelector: banner; // Usage .@{mySelector} { font-weight: bold; ...

  9. thinkphp多表查询

    在学习thinkphp 的过程中,需要对多表进行操作,但是在实际过程中,总是遇到各种问题,所以写下这篇博文,作为自己的学习历程 在操作过程中,两表查询都没有问题,但是三表查询就开始出现问题 有以下三张 ...

  10. bootstrap框架应用

    ---------------------------------------------------------------bootstrap---------------------------- ...