模拟 Codeforces620F Xors on Segments
来源:互联网 发布:电信机顶盒装软件 编辑:程序博客网 时间:2024/05/16 14:41
传送门:点击打开链接
题意:n个数,m次查询。n<=5e4,m<=1e3
每次查询为一个区间l,r,要在n的数的[l,r]区间内选出2个数a,b(a<=b),然后计算a^(a+1)^(a+2)^...^b,输出最大的这个值
思路:标准答案好像是莫队算法+trie
不过好多人复杂度都是O(n(n+m))的,,Tourist也是。。
只要你敢写就能过。大概就是i枚举第一个数a,然后j枚举第二个数b,mx记录另一个数所在的数组范围在[i,j]的对应的函数的最大值。
遍历所有的查询,看i是否在某个查询的区间范围内,如果在,那么就更新答案。
#include<map>#include<set>#include<cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<cctype>#include<string>#include<vector>#include<cstring>#include<iomanip>#include<iostream>#include<algorithm>#include<functional>#define fuck(x) cout<<"["<<x<<"]"#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w+",stdout)using namespace std;typedef long long LL;typedef pair<int, int>PII;const int MAX = 1e6 + 5;const int MX = 5e4 + 5;const int mod = 1e9 + 7;const int INF = 0x3ff3f3f;int z[MAX], A[MX], B[MX];int L[MX], R[MX], ans[MX];int main() { int n, m; //FIN; z[0] = 0; for(int i = 1; i < MAX; i++) z[i] = z[i - 1] ^ i; while(~scanf("%d%d", &n, &m)) { memset(ans, 0, sizeof(ans)); 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++) { if(A[i] <= A[j]) { mx = max(mx, z[A[j]] ^ z[A[i] - 1]); }else mx = max(mx, z[A[j] - 1] ^ z[A[i]]); B[j] = mx; } for(int k = 1; k <= m; k++) { if(L[k] <= i && i <= R[k]) { ans[k] = max(ans[k], B[R[k]]); } } } for(int i = 1; i <= m; i++) { printf("%d\n", ans[i]); } } return 0;}
0 0
- 模拟 Codeforces620F Xors on Segments
- Codeforces 620F Xors on Segments DP
- Codeforces edu 6. F Xors on Segments 枚举 优化技巧
- 【Codeforces837G】Functions On The Segments
- Segments
- Segments
- Segments
- Segments
- Segments
- awr中的Segments by Row Lock Waits模拟
- CodeForces 612D - The Union of k-Segments(模拟)
- nutch on hadoop 遇到 ls: 无法访问data/segments: 没有那个文件或目录
- SegLink on github-Detecting Oriented Text in Natural Images by Linking Segments
- Educational Codeforces Round 26 G. Functions On The Segments 主席树
- CF198 div1 D - Iahub and Xors
- 1991Segments
- using segments
- Gstreamer Segments
- 优先队列
- JAVA-JSP/Servlet 笔记(九)
- web图片或者上传
- 分类器的评价
- 5-24 约分最简分式
- 模拟 Codeforces620F Xors on Segments
- 单例
- tomcat 修改端口为80
- matlab画图,变长坐标轴
- MySQL多表连接删除问题相关
- 【HDU】 2795 Billboard
- AdSupport(简介)
- C++面试题(一)
- GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git分支 标签 过滤 Git版本工作流