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. WebStrom直接启动VUE项目

    点Run即可启动

  2. 通过read()读文件

    一.在POSIX中的定义 #include <unistd.h> ssize_t read(int fd, void *buf, size_t len); 二.调用read()的可能结果 ...

  3. Telnet Protocol Specification

    Network Working Group J. Postel Request for Comments: 854 J. Reynolds ISI Obsoletes: NIC 18639 May 1 ...

  4. HAX kernel module is not installed

    dev.android.emulator.haxm 运行emulator -avd xxx来启动名为xxx的模拟器,但报如下错误: emulator: ERROR: x86 emulation cur ...

  5. luogu P2331 [SCOI2005]最大子矩阵

    传送门 \[\huge\mathit{warning}\] \[\small\text{以下说明文字高能,请心脏病,,,,,,人士谨慎观看,请未成年人在家长陪同下观看}\] 皮这一下很开心 其实是代码 ...

  6. HDU2255 奔小康赚大钱 【KM算法】

    题意: 每个人对不同房有不同出价,就是就是怎样匹配卖房让收入达到最大. 思路: 建立二分图,一边为N家老百姓,还有一边为N间房子.对老百姓和房子之间估价建立一条有带权边.问题就转变为了再二分图中找出一 ...

  7. Ngnix + Tomcat负载均衡架构

    一.nginx Nginx (发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.  其特点是占有内 ...

  8. centOS6.4 extundelete工具恢复rm -rf 删除的目录[转]

    原文:http://www.cnblogs.com/patf/p/3368765.html PS:补充下,我在fedora 19上运行的时候遇到的一个问题: 1 [root@localhost ext ...

  9. Linux搜索查找类指令

    ⒈find [搜索范围] [选项] find指令将从指定目录下递归的遍历其各个子目录,将满足条件的文件或者目录显示在终端 选项说明: 选项 功能 -name<查询方式> 按照指定的文件名查 ...

  10. STM32F103X datasheet学习笔记---GPIOs and AFIOs

    1.前言 每个GPIO端口有如下几个寄存器进行操作: 两个32位配置寄存器:GPIOx_CRL, GPIOx_CRH 两个32位数据寄存器:GPIOx_IDR, GPIOx_ODR 一个32位set/ ...