HDU.6186.CSCource.(前缀和数组和后缀和数组)
明天后天是南昌赛了嘤嘤嘤,这几天就先不更新每日题目了,以后补题嘤嘤嘤。
今天和队友做了一套2017年广西邀请赛,5个题还是有点膨胀......
好了,先来说一下有意思的题目吧......
CS Course
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3450 Accepted Submission(s): 1287
Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.
Here is the problem:
You are giving n non-negative integers a1,a2,⋯,an, and some queries.
A query only contains a positive integer p, which means you
are asked to answer the result of bit-operations (and, or, xor) of all the integers except ap.
Each test case begins with two positive integers n and p
in a line, indicate the number of positive integers and the number of queries.
2≤n,q≤105
Then n non-negative integers a1,a2,⋯,an follows in a line, 0≤ai≤109 for each i in range[1,n].
After that there are q positive integers p1,p2,⋯,pqin q lines, 1≤pi≤n for each i in range[1,q].
1 1 1
1
2
3
1 1 0
1 1 0
#include <cstdio>
using namespace std; const int maxn = + ;
int c[maxn], _and1[maxn], _and2[maxn], _or1[maxn], _or2[maxn], _xor1[maxn], _xor2[maxn]; int main() {
int n, p, q, ans1, ans2, ans3;
while(~scanf("%d %d", &n, &p)) {
for(int i = ; i <=n; i ++) {
scanf("%d", &c[i]);
}
_and1[] = _or1[] = _xor1[] = c[];
_and2[n] = _or2[n] = _xor2[n] = c[n];
for(int i = ; i <= n; i ++) {
_and1[i] = _and1[i - ] & c[i];
_or1[i] = _or1[i - ] | c[i];
_xor1[i] = _xor1[i - ] ^ c[i];
}
for(int i = n - ; i >= ; i --) {
_and2[i] = _and2[i + ] & c[i];
_or2[i] = _or2[i + ] | c[i];
_xor2[i] = _xor2[i + ] ^ c[i];
} for(int i = ; i < p; i ++) {
scanf("%d", &q);
if(q == ) {
ans1 = _and2[];
ans2 = _or2[];
ans3 = _xor2[];
} else if(q == n) {
ans1 = _and1[n - ];
ans2 = _or1[n - ];
ans3 = _xor2[n - ];
} else {
ans1 = _and1[q - ] & _and2[q + ];
ans2 = _or1[q - ] | _or2[q + ];
ans3 = _xor1[q - ] ^ _xor2[q + ];
}
printf("%d %d %d\n", ans1, ans2, ans3);
}
}
return ;
}
HDU.6186.CSCource.(前缀和数组和后缀和数组)的更多相关文章
- HDU 5442 Favorite Donut(暴力 or 后缀数组 or 最大表示法)
http://acm.hdu.edu.cn/showproblem.php?pid=5442 题意:给出一串字符串,它是循环的,现在要选定一个起点,使得该字符串字典序最大(顺时针和逆时针均可),如果有 ...
- 【HDU 5030】Rabbit's String (二分+后缀数组)
Rabbit's String Problem Description Long long ago, there lived a lot of rabbits in the forest. One d ...
- Java数据结构和算法(六)——前缀、中缀、后缀表达式
前面我们介绍了三种数据结构,第一种数组主要用作数据存储,但是后面的两种栈和队列我们说主要作为程序功能实现的辅助工具,其中在介绍栈时我们知道栈可以用来做单词逆序,匹配关键字符等等,那它还有别的什么功能吗 ...
- Java数据结构和算法(六):前缀、中缀、后缀表达式
前面我们介绍了三种数据结构,第一种数组主要用作数据存储,但是后面的两种栈和队列我们说主要作为程序功能实现的辅助工具,其中在介绍栈时我们知道栈可以用来做单词逆序,匹配关键字符等等,那它还有别的什么功能吗 ...
- [TJOI2015]弦论(后缀数组or后缀自动机)
解法一:后缀数组 听说后缀数组解第k小本质不同的子串是一个经典问题. 把后缀排好序后第i个串的本质不同的串的贡献就是\(n-sa[i]+1-LCP(i,i-1)\)然后我们累加这个贡献,看到哪一个串的 ...
- hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点)
hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点) 题意: 给一张无向连通图,有两种操作 1 u v 加一条边(u,v) 2 u v 计算u到v路径上桥的个数 ...
- 温故而知新_C语言_前缀++(--)和后缀++(--)
前缀++(--)和后缀++(++)是有区别的. 再单独使用的时候是没有区别的,都是自身递增或者递减1. 但是综合使用起来会一样吗? 下面的例子都是++,替换成--也是一样,道理都是一样的. 请先看下面 ...
- HDU 1024 A - Max Sum Plus Plus DP + 滚动数组
http://acm.hdu.edu.cn/showproblem.php?pid=1024 刚开始的时候没看懂题目,以为一定要把那n个数字分成m对,然后求m对中和值最大的那对 但是不是,题目说的只是 ...
- HDU 5792:World is Exploding(树状数组求逆序对)
http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Problem Description Given a sequ ...
随机推荐
- Qt的ui->setupUi(this)在做什么?
ui->setupUi() 新建好Qt的工程之后,总是会在MainWindow函数中有一行代码 ui->setupUi(this); 跟踪进这行代码 class Ui_MainWindow ...
- spring 管理bean
目录结构: Person.java package com.wss.entity; import com.wss.service.doHomeWork; public class Person { p ...
- thinkphp5.0.19 request
一.请求类型 request类中 [F:\phpStudy\WWW\csweb\thinkphp\library\think\Request.php] 获取请求类型的方法分别是: isGet() .i ...
- 模型监控指标- 混淆矩阵、ROC曲线,AUC值,KS曲线以及KS值、PSI值,Lift图,Gain图,KT值,迁移矩阵
1. 混淆矩阵 确定截断点后,评价学习器性能 假设训练之初以及预测后,一个样本是正例还是反例是已经确定的,这个时候,样本应该有两个类别值,一个是真实的0/1,一个是预测的0/1 TP(实际为正预测为正 ...
- overload(重载) 和 override(重写)的区别
overload(重载): 重载是基于一个类中,方法名相同,参数列表不同(如果参数列表相同时,参数的类型要不同),与返回值和访问修饰符都无关 如果在面试中就直接说:"同名不同参" ...
- SSM图片
非关系型数据,redis,mongoDB关系型数据,mysql,oracle 1.springmvc+spring+mybatis1.导入jar2.书写配置xml(applicationContext ...
- Thread的几种方法的使用
1:setPriority() 设置线程的优先级,从1 到10. 5是默认的. 1是最低优先级. 10是最高优先级 public class MyThread01 implements Runn ...
- Laya 首日红点逻辑
Laya 首日红点逻辑 @author ixenos 2019-08-26 10:50:27 1.原理:显然,首日红点意味着包含进程销毁的情况,那么就要持久化存储信息,这里我们使用LocalStora ...
- 从源码编译UE4,加快Setup.bat下载文件的环节
之前很傻,每次运行这个setup.bat都要等很久很久才能把4g多的东西下载完成,知道有一天突然发现了世外桃源…… 从命令行运行setup.bat -help,可以看到参数的说明(没错,参数可选,之前 ...
- Spring Cloud架构教程 (八)消息驱动的微服务(消费组)【Dalston版】
使用消费组实现消息消费的负载均衡 通常在生产环境,我们的每个服务都不会以单节点的方式运行在生产环境,当同一个服务启动多个实例的时候,这些实例都会绑定到同一个消息通道的目标主题(Topic)上. 默认情 ...