Educational Codeforces Round 6 F. Xors on Segments 暴力
F. Xors on Segments
题目连接:
http://www.codeforces.com/contest/620/problem/F
Description
You are given an array with n integers ai and m queries. Each query is described by two integers (lj, rj).
Let's define the function . The function is defined for only u ≤ v.
For each query print the maximal value of the function f(ax, ay) over all lj ≤ x, y ≤ rj, ax ≤ ay.
Input
The first line contains two integers n, m (1 ≤ n ≤ 5·104, 1 ≤ m ≤ 5·103) — the size of the array and the number of the queries.
The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
Each of the next m lines contains two integers lj, rj (1 ≤ lj ≤ rj ≤ n) – the parameters of the j-th query.
Output
For each query print the value aj on a separate line — the maximal value of the function f(ax, ay) over all lj ≤ x, y ≤ rj, ax ≤ ay.
Sample Input
6 3
1 2 3 4 5 6
1 6
2 5
3 4
Sample Output
7
7
7
Hint
题意
题目中定义了f(i,j) = i(i+1)(i+2)...j
给你n个数,然后m次询问
每次问你l,r区间内,f(a[i],a[j])最大是多少,l<=i,j<=r
题解:
正解的话是莫队+字典树
复杂度是(n+m)lognsqrt(n)
但是这道题也有(n^2+nm)的算法,两个算法的复杂度差距不是很大
并且第二种好写的多……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
int f[maxn];
int a[maxn];
int G[maxn];
int l[maxn],r[maxn],ans[maxn];
int main()
{
for(int i=1;i<maxn;i++)
f[i]=f[i-1]^i;
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d%d",&l[i],&r[i]);
for(int i=1;i<=n;i++)
{
int mx = 0;
for(int j=i;j<=n;j++)
{
int cnt = f[a[j]]^f[a[i]];
if(a[j]>a[i])
cnt^=a[i];
else
cnt^=a[j];
mx = max(cnt,mx);
G[j]=mx;
}
for(int j=1;j<=m;j++)
if(l[j]<=i&&i<=r[j])
ans[j]=max(ans[j],G[r[j]]);
}
for(int i=1;i<=m;i++)
printf("%d\n",ans[i]);
}
Educational Codeforces Round 6 F. Xors on Segments 暴力的更多相关文章
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- Educational Codeforces Round 51 F. The Shortest Statement(lca+最短路)
https://codeforces.com/contest/1051/problem/F 题意 给一个带权联通无向图,n个点,m条边,q个询问,询问两点之间的最短路 其中 m-n<=20,1& ...
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
- Educational Codeforces Round 26 F. Prefix Sums 二分,组合数
题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...
- Educational Codeforces Round 9 F. Magic Matrix 最小生成树
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...
- Educational Codeforces Round 7 F. The Sum of the k-th Powers 拉格朗日插值法
F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description Ther ...
- Educational Codeforces Round 8 F. Bear and Fair Set 最大流
F. Bear and Fair Set 题目连接: http://www.codeforces.com/contest/628/problem/F Description Limak is a gr ...
- Educational Codeforces Round 14 - F (codeforces 691F)
题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围: ...
随机推荐
- 关于might_sleep的一点说明【转】
转自:http://blog.csdn.net/chen_chuang_/article/details/48462575 这个函数我在看代码时基本上是直接忽略的(因为我知道它实际上不干什么事),不过 ...
- mac系统中实现vitualBox中访问内网端口
第一步,增加外网网段 打开vitualbox后,按管理菜单,点击->主机网络管理器,如图1所示.点击创建,创建下个网络主机. 图1 然后,关掉虚拟机,虚拟机的设置中,找到网络选项卡,然后点击网络 ...
- IoT之车联网
一. 背景 这是一个笔者在实习公司策划的关于车联网的小项目,也是笔者参加某竞赛的作品<基于云平台的车内滞留儿童状况监测与处理>,本项目旨在为因各种原因导致儿童滞留车内热死.闷死的社会性事件 ...
- HA集群
//硬件准备: .两个机器,相同系统 .网卡ip为:aming 192.168.11.24 aming1 192.168.11.23 //实验准备: . hostname : aming , amin ...
- vim常用命令(复习版)(转)
原文链接:http://blog.csdn.net/love__coder/article/details/6739670 1.光标移动 上:k 下:j 左:l 『字母L小写』 右:h 上一行行首:- ...
- git+jenkins在windows机器上新建一个slave节点【转载】
转至博客:上海-悠悠 前言 我们在跑自动化项目的时候,希望有单独的测试机能跑自动化项目,并且能集成到jenkins上构建任务.如果公司已经有jenkins环境了,那无需重新搭建. 只需在现有的平台基础 ...
- memcached安装+绑定访问ip
安装: 1.由于memcached是基于libevent的,需要安装libevent,libevent-devel $yum -y install libevent libevent-devel 2. ...
- Go语言的web程序写法
一切来自于扩展... 核心也即处理输入输出... // helloworld project main.go package main import ( "fmt" "h ...
- Go语言标准库之log包
用来作日志log输出的, 比较易懂. 今天周六啊,在公司加班学习一下呀. package main import ( "log" ) func init() { log.SetPr ...
- 解决ssh登录过慢问题
1.首先打开debug,看看慢在哪里 [root@BC-NFS1 ~]# ssh -v root@192.168.102.41 -p 22 OpenSSH_6.6.1, OpenSSL 1.0.1e- ...