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 数据范围: ...
随机推荐
- python中的ftplib模块
前言 Python中默认安装的ftplib模块定义了FTP类. ftplib模块相关参数: 加载ftp模块:from ftplib import FTP ftp = FTP()#设置变量ftp.set ...
- html meta标签作用
1.概要 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他web服务. 必要属性: conten ...
- centos_7.1.1503_src_1
http://vault.centos.org/7.1.1503/os/Source/SPackages/ 389-ds-base-1.3.3.1-13.el7.src.rpm 31-Mar-2015 ...
- twemproxy 简介、安装配置
twemproxy 简介.安装配置 http://www.xuchanggang.cn/archives/993.html
- Pylot网站Web服务器性能和负载压力测试-适用Windows可绘制图表
为了能够准确地评估网站服务器对网络流量的承受能力,我们一般会采取模拟网站用户访问,通过不断地增加并发数,延长访问时长,从而最终得出网站Web服务器的性能和负载能力.当然也可以通过Web压力测试,来完善 ...
- Django web框架之权限管理二
1. login登录 def login(request): if request.method=="GET": return render(request,'login.html ...
- hdu 1664(数论+同余搜索+记录路径)
Different Digits Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Convolutional Neural Networks卷积神经网络
转自:http://blog.csdn.net/zouxy09/article/details/8781543 9.5.Convolutional Neural Networks卷积神经网络 卷积神经 ...
- 一个前端资源站 http://www.bootcss.com/
http://www.bootcss.com/ 里面有w3schools原版的镜像网站地址: https://www.quanzhanketang.com/ 这个网站正常版本被墙了,可以通过这个镜像访 ...
- (翻译)Xamarin.Essentials 最新预览版的更多跨平台 API
原文地址:https://blog.xamarin.com/cross-platform-apis-xamarin-essentials-latest-preview/ 在 Microsoft Bui ...