【HDOJ】5288 OO’s Sequence
二分寻找对于指定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的更多相关文章
- 【HDOJ】5063 Operation the Sequence
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...
- 【HDOJ】5057 Argestes and Sequence
树状数组,其实很简单.只是MLE. #include <iostream> #include <cstdio> #include <cstring> using n ...
- 思维题 HDOJ 5288 OO’s Sequence
题目传送门 /* 定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置, 第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i] ...
- 【BZOJ1345】[Baltic2007]序列问题Sequence 贪心+单调栈
[BZOJ1345][Baltic2007]序列问题Sequence Description 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和a ...
- 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 ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- HDOJ 5288 OO’s Sequence 水
预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
随机推荐
- iis的路径
每次打开iis管理器查看iis指定路径下的文件过于麻烦,而且iis管理器耗资源,以下是iis的路径,以及其对应在本地磁盘的地址 SP2013\Sites\SharePoint - 80\_contro ...
- 20160406javaweb 之JDBC简单案例
前几天写的user注册登录注销案例,没有用到数据库,现在做出改动,使用数据库存储信息: 一.首先我们需要建立一个数据库: 如下图: 创建数据库的代码如下: -- 导出 database02 的数据库结 ...
- c语言学习之基础知识点介绍(十三):枚举的介绍和使用
一.枚举的介绍 /* 枚举:限制的待选项. 语法: enum 枚举名{ 选项1, 选项2, 选项3, ........ 选项n }; 注意:枚举中,选项之间用 , 隔开,最后一个不用加 , :并且枚举 ...
- 在.Net中进行跨线程的控件操作(下篇:BackgroundWorker)
在.Net中,如果我们在非UI线程上访问窗体上的控件的时候,会产生一个跨线程调用的异常,那么如何处理这种情况呢?在上一章中,我介绍了使用Control.Invoke方法,如果你不习惯使用委托,那么.N ...
- 100个iOS开发面试题汇总-王刚韧的技术博客
100个iOS开发面试题汇总 关于iOS开发面试,不管对于招聘和应聘来说,面试都是很重要的一个环节,特别对于开发者来说,面试中的技术问题环节不仅是企业对应聘者技能和积累的考察,也是一个开发者自我检验的 ...
- Net中exe之间的消息传递
1.创建一个消息通讯类 using System;using System.Collections.Generic;using System.Linq;using System.Text;using ...
- HDU 1176 免费馅饼(数字三角形)
免费馅饼 Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉 ...
- HDU 1175 连连看(BFS)
连连看 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模
题目地址:http://ac.jobdu.com/problem.php?pid=1085 题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k). ...
- tomcat内存溢出问题
内存泄露java.lang.OutOfMemoryError: PermGen space解决办法 今天访问web服务器,tomcat服务就瘫痪了,通过查看日志,发现java.lang.OutOfMe ...