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. 一个简单的"RPC框架"代码分析

    0,服务接口定义---Echo.java /* * 定义了服务器提供的服务类型 */ public interface Echo { public String echo(String string) ...

  2. castle动态代理的使用

    转自:https://blog.csdn.net/educast/article/details/6565447#动态代理的原理 原理其实很简单,就是在运行时生成新的对象,姑且叫做T,并使T继承自需要 ...

  3. Nginx 日志处理

    . nginx日志统计独立ip的个数: awk '{print $1}' /access.log | sort | uniq | wc -l . 查询访问最多的前10个ip awk . 查看某段时间的 ...

  4. 修改mysql的用户root密码

    第一种方法:root用户登录系统/usr/local/mysql/bin/mysqladmin -u root -p password 新密码enter password 旧密码 第二种方法:root ...

  5. 【文件】使用jacob将word转换成pdf格式

    使用jacob将word转换成pdf格式   1.需要安装word2007或以上版本,若安装07版本学确保该版本已安装2downbank0204MicrosoftSaveasPDF_ XPS,否则安装 ...

  6. img格式镜像转ISO格式

    在做汇编学习时,需要用比较老的Windows XP来进行调试学习,因此找了最老的Windows XP(CN_WINXP_PRO_ISO,无SP版本 ),下载后发现镜像文件格式是img的,而virtua ...

  7. URLSession

    URLSession时ios7中的心得网络接口,与NSURLConnection是并列的. 当程序在前台时,URLSession与NSURLConnection大部分可以互相替代. URLSessio ...

  8. linux 下安装 oracle

    http://yourcouner.blog.51cto.com/59520/91156 一.RedHat AS4系统安装: 磁盘配置: 设备 类型 大小 / ext3 39911 swap 1024 ...

  9. <crtdbg.h> 的作用

    1.在调试状态下让win程在输出窗口中显示调试信息,可以用_RPTn 宏n为显示参数比如_RPT0(_CRT_WARN,"text"); _RPT1(_CRT_WARN," ...

  10. MongoDB的基本概念

    MongoDB的基本概念 库 db就是数据库 文档就是数据表的行 集合就是数据表,这个没有模式,啥叫没有模式呢,就是没有列的定义,随便什么属性都行,这点就比关系行数据库牛逼10000000倍,逆天了.