博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spoj TBATTLE 质因数分解+二分
阅读量:5291 次
发布时间:2019-06-14

本文共 2950 字,大约阅读时间需要 9 分钟。

题目链接:

TBATTLE - Thor vs Frost Giants

 

 

Thor is caught up in a fierce battle with Loki's army. This army consists of frost giants that have magical powers with them. Their strength levels gets multiplied when they are together. Giants are not highly skilled in the arts of combat, but their sheer size and strength make them formidable opponents even for the Asgardian gods. Thor is no exception. They recover very fast from physical injury but their recovery slows down when they are exposed to extreme heat. 

Thor's hammer can generate heat only in multiples of heat quantum N. Frost giants get killed only when their combined strength level is exactly equal to the heat level of the hammer. Thor is interested in killing a continuous stretch of frost enemies with a throw of his hammer with a preference to kill closer enemies first.
Continuous stretch is defined as a set of consecutive elements.
Help Thor to determine the minimum stretch of frost giants that could be killed in a throw. In case of multiple minimal stretches, output the indices of that stretch that has lowest starting index. If there is no such continuous stretch possible then print -1.

Input

The first line will contain N, the number of Frost Giants in Loki's army and the Heat quantum.

The second line will contain N integers (a_0, a_2....., a_n-1) - the strength of each frost giant. 
Minimum stretch of the army should be 1.

  • 1 ≤ N ≤ 100000
  • 1 ≤ a_i ≤ 100000

Output

Output the range of the minimum stretch of frost giants that could be killed in a throw. In case of multiple minimal stretches, output the indices of that stretch that has lowest starting index.

If there is no such continuous stretch possible then print -1.

Example

Input:31 2 9Output: 2 2 Input: 5 2 3 4 8 9Output: -1 Input:102 4 3 5 17 4 7 5 2 15 Output: 7 8

Explanation

Input #1:

Thor can only kill the stretch [2,2] as this is the minimum length range with strength, multiple of 3.

Input #2:

There is no stretch of frost giants that have combined strength as a multiple of 5.

Input #3:

There are many stretches of frost giants that have strength as multiple of 10. But the minimal stretch with the least indices is from [7,8]. Minimum size stretches are [7, 8] and [8, 9]. Out of them we select [7,8].

 

 
#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long long#define pi (4*atan(1.0))#define eps 1e-14#define bug(x) cout<<"bug"<
<
p;int n;int c[20];void init(int n){ memset(c,0,sizeof(c)); int si=0; for(int i=2;i<=n;i++) { if(n%i==0)p.push_back(i),si++; while(n%i==0) { c[si-1]++; n/=i; } }}int sum[N][20];int check(int l,int r){ for(int j=0;j
>1; if(check(i,mid)) { ans=mid; en=mid-1; } else st=mid+1; } if(ans!=-1) { if(ans-i

 

转载于:https://www.cnblogs.com/jhz033/p/6659790.html

你可能感兴趣的文章
cf--------(div1)1A. Theatre Square
查看>>
Android面试收集录15 Android Bitmap压缩策略
查看>>
PHP魔术方法之__call与__callStatic方法
查看>>
ubuntu 安装后的配置
查看>>
Html学习_简易个人网页制作
查看>>
angular中ng-bind指令小案例
查看>>
jqery总结
查看>>
Lodop获取客户端主网卡ip地址是0.0.0.0
查看>>
VSCODE更改文件时,提示:EACCES: permission denied的解决办法(mac电脑系统)
查看>>
web前端之路,js的一些好书(摘自聂微东 )
查看>>
【模板】对拍程序
查看>>
微信小程序开发初体验
查看>>
dos批处理(bat)运行exe
查看>>
关键字
查看>>
Pycharm安装Markdown插件
查看>>
上传图片并预览
查看>>
哈夫曼编码_静态库
查看>>
【转】redo与undo
查看>>
C#更新程序设计
查看>>
常用Request对象获取请求信息
查看>>