Case of a Top Secret

感觉除了两个点在那循环的部分, 其他时候绳子的长度每次变为一半一下, 就变成了Log(l)步。。

然后就暴力找就好啦, 循环的部分取个模。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m, a[N], x[N], id[N]; bool cmp(const int& a, const int& b) {
return x[a] < x[b];
}
int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
x[i] = a[i];
id[i] = i;
}
sort(id + , id + + n, cmp);
sort(x + , x + + n);
while(m--) {
int p, l;
scanf("%d%d", &p, &l);
while() {
int be = p, len = ;
int it1 = upper_bound(x + , x + + n, a[p] + l) - x - ;
len += abs(x[it1] - a[p]);
l -= abs(x[it1] - a[p]);
p = id[it1];
int it2 = lower_bound(x + , x + + n, a[p] - l) - x;
len += abs(x[it2] - a[p]);
l -= abs(x[it2] - a[p]);
p = id[it2];
int ed = p;
if(be == ed && be == id[it1]) {
break;
}
if(be == ed) {
l %= len;
}
}
printf("%d\n", p);
}
return ;
} /*
*/

Codeforces 555D Case of a Top Secret的更多相关文章

  1. Codeforces Round #327 (Div. 1) D. Top Secret Task

    D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces 590D Top Secret Task

    D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  4. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  5. codeforces 555B Case of Fugitive

    题目连接: http://codeforces.com/problemset/problem/555/B 题目大意: 有n个岛屿(岛屿在一列上,可以看做是线性的,用来描述岛屿位置的是起点与终点),m个 ...

  6. CodeForces - 556D Case of Fugitive (贪心+排序)

    Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet ...

  7. Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集

    D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...

  8. codeforces 556C. Case of Matryoshkas 解题报告

    题目链接:http://codeforces.com/contest/556/problem/C 题目意思:有 n 个数(1,2,...,n)组成 k 条链.第 i 条链由 mi 个数组成.每一秒只可 ...

  9. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

随机推荐

  1. Hibernate_day01

    一.今天内容介绍 1 web内容回顾 (1)javaee三层结构 (2)mvc思想 2 hibernate概述 3 hibernate入门案例 4 hibernate配置文件 5 hibernate的 ...

  2. Python实现Plugin

    1. Plugin与Python 插件的历史最早可追溯至1970年代,它是一种程序组件,通过和应用程序的互动,为应用程序增加一些所需要的特定的功能[维基].插件允许第三方开发者对已有的程序功能进行扩展 ...

  3. QDialog对话框

    QDialog对话框,用来实现那些只是暂时存在的用户界面,是独立的窗口,但通常也有父窗口对话框有模态和非模态两种,,非模态对话框的行为和使用方法都类似于普通的窗口,模态对话框则有所不同,当模态对话框显 ...

  4. luogu P3304 [SDOI2013]直径

    树的直径两遍dfs救星了 至于一定在直径中的边数,可以发现这些边一定是连续的(不然你两条直径中间能有空挡?),然后,如果某个点往下有多条直径,那么这条点以下都不算入答案.所以以直径分别两端点为根,找出 ...

  5. 【SVN】svn使用方法

    下载安装TortoiseSVN 下载地方 安装成功后 TortoiseSVN清除凭证 右击空白处-TortoiseSVN-Settings打开Settings窗口后做如下操作: svn在idea中的使 ...

  6. printf 函数的实现原理

    /* * ===================================================================================== * * Filen ...

  7. BroadcastReceiver的两种注册方式和使用

    1.静态注册,在minifest文件中 <receiver android:name=".BroadcastReceiverDemo" > <intent-fil ...

  8. systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

    1.centos 检查服务是否开机自启  (ntpd是原生的服务,mysql是注册的服务) 参考:1.http://man.linuxde.net/systemctl

  9. LOJ 2567: 洛谷 P3643: bzoj 4584: 「APIO2016」划艇

    题目传送门:LOJ #2249. 题意简述: 有 \(n\) 个位置,第 \(i\) 个位置可以填在 \([a_i,b_i]\) (\(1\le a_i\le b_i\le 10^9\))之间的整数, ...

  10. CentOS配置SSH无密码

    210-211/212/213的集群中,新增215节点,操作:1.将210的id_rsa.pub拷贝到215中:scp ~/.ssh/id_rsa.pub 192.168.0.215@host:/ho ...