arc060 E - Tak and Hotels
E - Tak and Hotels
先找到每个点一步最远跳到哪个点,然后用个倍增即可
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define sc second
#define pb push_back
#define ll long long
#define trav(v,x) for(auto v:x)
#define all(x) (x).begin(), (x).end()
#define VI vector<int>
#define VLL vector<ll>
#define pll pair<ll, ll>
#define double long double
//#define int long long
using namespace std;
const int N = 1e6 + 100;
const int inf = 1e9;
//const ll inf = 1e18;
const ll mod = 998244353;//1e9 + 7;#ifdef LOCAL
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << " " << to_string(H);debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endifvoid sol()
{ll n, m;cin >> n;VLL a(n);for(int i = 0; i < n; i++)cin >> a[i];cin >> m;vector<VLL> jp(n, VLL(20, 0));for(int i = n - 1; i >= 0; i--){if(i == n - 1){for(int j = 0; j < 20; j++)jp[i][j] = n;continue;}int x = upper_bound(all(a), a[i] + m) - a.begin();--x;jp[i][0] = x;for(int j = 1; j < 20; j++)jp[i][j] = (jp[i][j - 1] == n ? n : jp[jp[i][j - 1]][j - 1]);}int qq;cin >> qq;while(qq--){int x, y;cin >> x >> y;--x, --y;if(x > y)swap(x, y);int ans = 0;for(int i = 19; i >= 0; i--){if(jp[x][i] <= y)x = jp[x][i], ans += 1 << i;}if(x < y)++ans;cout << ans << '\n';}
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);
// int tt;
// cin >> tt;
// while(tt--)sol();
}
arc060 E - Tak and Hotels相关推荐
- ARC060 E Tak and Hotels 倍增
题目链接 题意: 给你 n n n个坐标,要求每次移动不超过 l l l,并且每次移动后一定要到这 n n n个坐标中的某一个.有 q q q次询问,每次询问一对点 a , b a,b a,b,求从 ...
- 6463: Tak and Hotels II
6463: Tak and Hotels II 时间限制: 1 Sec 内存限制: 128 MB 提交: 95 解决: 29 [ 提交][ 状态][ 讨论版][命题人: admin] 题目描述 ...
- [AtCoder Regular Contest 060] E - Tak and Hotels
AT2039 [ARC060C] 高橋君とホテル / Tak and Hotels problem solution - 分块 code - 分块 solution - 倍增 code - 倍增 pr ...
- Tak and Hotels II【倍增】
Tak and Hotels II 时间限制: 1 Sec 内存限制: 128 MB 提交: 140 解决: 38 [提交] [状态] [命题人:admin] 题目描述 N hotels are lo ...
- 6463: Tak and Hotels II(倍增)
题目描述 N hotels are located on a straight line. The coordinate of the i-th hotel (1≤i≤N) is xi. Tak th ...
- 高橋君とホテル / Tak and Hotels(AtCoder-2039)
Problem Description N hotels are located on a straight line. The coordinate of the i-th hotel (1≤i≤N ...
- ARC060 C - Tak and Cards(dp,背包)
题意: 解法: 令d[i][j][k]表示前i个物品,选j个,总和为k的方案数, 背包dp出来,最后答案为sum(d[n][i][i*A]).第一维可以滚动优化掉. code: #include &l ...
- atcoder题目合集(持续更新中)
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...
- AtCoder Regular Contest 060
文章目录 C - Tak and Cards D - Digit Sum E - Tak and Hotels F - Best Representation 比赛链接 C - Tak and Car ...
最新文章
- nginx+tomcat+memcache实现负载均衡、session共享
- [html] Google map的地理编码javascript例子 -- Google map geocoder example
- 112家it公司薪水
- 获取二进制或者16/32位的某一位的值
- 渗透测试报告标准编写
- python的render函数_带函数return的Flask render_模板
- 失业日志:2009年10月12日星期一
- 2019 年的 Linux 会如何?
- postgreSQL数据库里面导入数据
- df 命令查看磁盘空间_Linux df命令检查磁盘空间
- Arrays.asList( ) 返回一个特殊的“ArrayList”
- 2021-05-23
- UC浏览器如何开启html5,如何开启手机uc浏览器中的极速模式
- 饥荒高脚鸟蛋孵化教程
- Linux GIC代码分析
- 微信小程序开发13 云开发:云原生一体化应用开发平台
- hMailServer 配置
- ibm aix 抓包命令_在IBM AIX上模拟丢弃的TCP / IP数据包
- 性能提升30倍丨基于 DolphinDB 的 mytt 指标库实现
- 2019届计算机专业-上海国企单位(银行、证券、通信)秋招经验大杂烩