博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hihoCoder #1831 : 80 Days-RMQ (ACM/ICPC 2018亚洲区预选赛北京赛站网络赛)
阅读量:5111 次
发布时间:2019-06-13

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

 

水道题目,比赛时线段树写挫了,忘了RMQ这个东西了(捞)

 

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

80 Days is an interesting game based on Jules Verne's science fiction "Around the World in Eighty Days". In this game, you have to manage the limited money and time.

Now we simplified the game as below:

There are n cities on a circle around the world which are numbered from 1 to n by their order on the circle. When you reach the city i at the first time, you will get ai dollars (ai can even be negative), and if you want to go to the next city on the circle, you should pay bi dollars. At the beginning you have c dollars.

The goal of this game is to choose a city as start point, then go along the circle and visit all the city once, and finally return to the start point. During the trip, the money you have must be no less than zero.

Here comes a question: to complete the trip, which city will you choose to be the start city?

If there are multiple answers, please output the one with the smallest number.

输入

The first line of the input is an integer T (T ≤ 100), the number of test cases.

For each test case, the first line contains two integers n and c (1 ≤ n ≤ 106, 0 ≤ c ≤ 109).  The second line contains n integers a1, …, an  (-109 ≤ ai ≤ 109), and the third line contains n integers b1, …, bn (0 ≤ bi ≤ 109).

It's guaranteed that the sum of n of all test cases is less than 106

输出

For each test case, output the start city you should choose.

提示

For test case 1, both city 2 and 3 could be chosen as start point, 2 has smaller number. But if you start at city 1, you can't go anywhere.

For test case 2, start from which city seems doesn't matter, you just don't have enough money to complete a trip.

样例输入
23 03 4 55 4 33 100-3 -4 -530 40 50
样例输出
2-1

 

 

题意就是一个环,每到一个点+a[i]-b[i],要求整个过程中值>=0,直接维护差值的前缀和就可以。

将环变成2倍长度,然后ST预处理就可以了。

 

代码:

1 //D-RMQ(ST) 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 using namespace std;21 typedef long long ll;22 23 const double PI=acos(-1.0);24 const double eps=1e-6;25 const ll mod=1e9+7;26 const int inf=0x3f3f3f3f;27 const int maxn=2e6+10;28 const int maxm=100+10;29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);30 #define lson l,m,rt<<131 #define rson m+1,r,rt<<1|132 33 ll a[maxn],pre[maxn],mi[maxn][25];34 35 void ST(int n)36 {37 for(int i=1;i<=n;i++){38 mi[i][0]=pre[i];39 }40 for(int j=1;(1<
<=n;j++){41 for(int i=1;i+(1<
<=n;i++) {42 mi[i][j]=min(mi[i][j-1],mi[i+(1<<(j-1))][j-1]);43 }44 }45 }46 47 ll RMQ(int l,int r)48 {49 int k=(int)(log(double(r-l+1))/log((double)2));50 return min(mi[l][k],mi[r-(1<
=0){75 ans=i;76 break;77 }78 }79 printf("%d\n",ans);80 }81 }

 

 

 

。。。

 

转载于:https://www.cnblogs.com/ZERO-/p/9756509.html

你可能感兴趣的文章
慵懒中长大的人,只会挨生活留下的耳光
查看>>
"远程桌面连接--“发生身份验证错误。要求的函数不受支持
查看>>
【BZOJ1565】 植物大战僵尸
查看>>
VALSE2019总结(4)-主题报告
查看>>
浅谈 unix, linux, ios, android 区别和联系
查看>>
51nod 1428 活动安排问题 (贪心+优先队列)
查看>>
中国烧鹅系列:利用烧鹅自动执行SD卡上的自定义程序(含视频)
查看>>
Solaris11修改主机名
查看>>
latex for wordpress(一)
查看>>
如何在maven工程中加载oracle驱动
查看>>
Flask 系列之 SQLAlchemy
查看>>
aboutMe
查看>>
【Debug】IAR在线调试时报错,Warning: Stack pointer is setup to incorrect alignmentStack,芯片使用STM32F103ZET6...
查看>>
一句话说清分布式锁,进程锁,线程锁
查看>>
python常用函数
查看>>
FastDFS使用
查看>>
服务器解析请求的基本原理
查看>>
[HDU3683 Gomoku]
查看>>
【工具相关】iOS-Reveal的使用
查看>>
数据库3
查看>>