codeforces 620F. Xors on Segments
定义一种操作f(u, v) = u^u+1^.......^v。 (u<=v), 给n个数, q个询问, 每个询问给出一个区间[l, r], 求这个区间里的f(a[i], a[j]) (l<=i<=j<=r)的最大值。
一开始竟然用n^2m的方法, 真是有点脑残..
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int a[], ans[], b[], dp[];
struct node
{
int l, r;
}q[];
int main()
{
int n, m;
cin>>n>>m;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
}
for(int i = ; i<=; i++) {
b[i] = i^b[i-];
}
for(int i = ; i<m; i++) {
scanf("%d%d", &q[i].l, &q[i].r);
}
for(int i = ; i<=n; i++) {
dp[i] = a[i];
for(int j = i+; j<=n; j++) {
int minn = min(a[i], a[j]);
int maxx = max(a[i], a[j]);
int num = b[maxx]^b[minn-];
dp[j] = max(dp[j-], num);
}
for(int j = ; j<m; j++) {
if(i>=q[j].l&&i<=q[j].r) {
ans[j] = max(ans[j], dp[q[j].r]);
}
}
}
for(int i = ; i<m; i++)
printf("%d\n", ans[i]);
return ;
}
codeforces 620F. Xors on Segments的更多相关文章
- Codeforces 620F Xors on Segments(暴力+DP)
题目链接 Xors on Segments 预处理出$x[i]$ $=$ $1$ $xor$ $2$ $xor$ $3$ $xor$ $……$ $xor$ $i$ 话说这题$O(n^{2})$居然能过 ...
- Educational Codeforces Round 6 F. Xors on Segments 暴力
F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...
- Xors on Segments Codeforces - 620F
http://codeforces.com/problemset/problem/620/F 此题是莫队,但是不能用一般的莫队做,因为是最优化问题,没有办法在删除元素的时候维护答案. 这题的方法(好像 ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
- Codeforces 193 D. Two Segments
http://codeforces.com/contest/193/problem/D 题意: 给一个1~n的排列,在这个排列中选出两段区间,求使选出的元素排序后构成公差为1的等差数列的方案数. 换个 ...
- Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...
- Codeforces 895.B XK Segments
B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【CodeForces】899 E. Segments Removal
[题目]E. Segments Removal [题意]给定n个数字,每次操作删除最长的连续相同数字(等长删最左),求全部删完的最少次数.n<=2*10^6,1<=ai<=10^9. ...
- 『ACM C++』 Codeforces | 1066A - Points in Segments
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...
随机推荐
- sqoop安装与使用
sqoop简介 sqoop名字是怎么来的?Sqoop: SQL-to-Hadoop 连接传统数据库和hadoop的桥梁,把关系型数据库的数据导入到hadoop系统(如HDFS,HBASE和hive中) ...
- 4.跟我学solr---SolrRequestHandler具体解释
概述 我们在使用solr admin在做查询的时候,能够看到Request-Hander(qt)输入栏中有"/select"这样一个uri.当我们点击查询的时候所发起的请求是这种. ...
- 应用程序正常初始化(0xc015002)失败解决方法
VS2005 sidebyside manifest error Microsoft.VC80.MFC Microsoft.VC80.CRT Microsoft.VC80.MFCLOC msvcr80 ...
- 从零开始学习UNITY3D(GUI篇)
邻近年底,心也有些散乱,加上工作忙了一阵,在达内培训的课程也落下了不少.对unity3d的热度似乎也有点点下降.痛定思痛,又在淘宝上买了写蛮牛网的视频.总之不管是用任何手段都要逼着自己不要浪费了培训的 ...
- mockjax MOCK.js的拦截ajax请求
今天看了下 mock.js的拦截请求 .https://github.com/nuysoft/Mock/blob/master/src/mockjax.js //覆盖(拦截) Ajax 请求,目前内置 ...
- sass 语法实例
sass基本语法 1.定义一个变量,变量定义以$开头,以冒号分隔开. $blue:#1875e7; div{ color:$blue; } 编译之后的css代码: div { color: #1875 ...
- c++ 调用DLL函数,出现错误
c++ 调用DLL函数,出现错误 Run-Time Check Failure #0 - The value of ESP was not properly saved across a funct ...
- UVa 116 Unidirectional TSP (DP)
该题是<算法竞赛入门经典(第二版)>的一道例题,难度不算大.我先在没看题解的情况下自己做了一遍,虽然最终通过了,思路与书上的也一样.但比书上的代码复杂了很多,可见自己对问题的处理还是有所欠 ...
- Aliyun EMR 集群重启
1.如果Core节点有Down掉,ActiveNodes少于Core节点数. 处理: a.登陆到Master节点,到目录 /opt/apps/hadoop-2.7.2/sbin b.执行 ./stop ...
- SQL1-(增删改查、常用函数)
USE flowershopdb --全球唯一标识符(GUID UUID) SELECT NEWID() --增删改查 --INSERT [INTO] <表名> [列名] VALUES & ...