Mahmoud and Ehab and yet another xor task

存在的元素的方案数都是一样的, 啊, 我好菜啊。

离线之后用线性基取check存不存在,然后计算答案。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define LD long double
  4. #define ull unsigned long long
  5. #define fi first
  6. #define se second
  7. #define mk make_pair
  8. #define PLL pair<LL, LL>
  9. #define PLI pair<LL, int>
  10. #define PII pair<int, int>
  11. #define SZ(x) ((int)x.size())
  12. #define ALL(x) (x).begin(), (x).end()
  13. #define fio ios::sync_with_stdio(false); cin.tie(0);
  14.  
  15. using namespace std;
  16.  
  17. const int N = 1e5 + ;
  18. const int inf = 0x3f3f3f3f;
  19. const LL INF = 0x3f3f3f3f3f3f3f3f;
  20. const int mod = 1e9 + ;
  21. const double eps = 1e-;
  22. const double PI = acos(-);
  23.  
  24. template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
  25. template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
  26. template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
  27. template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}
  28.  
  29. int n, q, a[N], ans[N];
  30. vector<int> base;
  31. vector<PII> qus[N];
  32.  
  33. int ok(int v) {
  34. for(auto& x : base) v = min(v, v ^ x);
  35. return v;
  36. }
  37.  
  38. int main() {
  39. scanf("%d%d", &n, &q);
  40. for(int i = ; i <= n; i++) scanf("%d", &a[i]);
  41. for(int i = ; i <= q; i++) {
  42. int l, x; scanf("%d%d", &l, &x);
  43. qus[l].push_back(mk(x, i));
  44. }
  45. int way = ;
  46. for(int i = ; i <= n; i++) {
  47. int val = ok(a[i]);
  48. if(!val) way = 1LL * way * % mod;
  49. else base.push_back(val);
  50. for(auto& q : qus[i]) ans[q.se] = ok(q.fi) ? : way;
  51. }
  52. for(int i = ; i <= q; i++) printf("%d\n", ans[i]);
  53. return ;
  54. }
  55.  
  56. /*
  57. */

Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)的更多相关文章

  1. 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线

    959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ...

  2. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  3. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  4. [CF959F]Mahmoud and Ehab and yet another xor task题解

    搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基. 然后一个num数组记录当时线性基里有多少数 然后每次前缀操作一下就珂以了 代码 #include <cs ...

  5. codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)

    题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质  2  字典序大于等于原数组  3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...

  6. D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学

    D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...

  7. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

  8. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  9. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

随机推荐

  1. Nginx 反向代理 负载均衡 虚拟主机

    Nginx 反向代理 负载均衡 虚拟主机配置 通过本章你将学会利用Nginx配置多台虚拟主机,清楚代理服务器的作用,区分正向代理和反向代理的区别,搭建使用Nginx反向搭理和负载均衡,了解Nginx常 ...

  2. luasocket编译安装遇到的坑

    由于需要获得本机的IP地址,所以需要 : local socket = require('socket') local server_hostname = socket.dns.gethostname ...

  3. 解决SkyP2M工程常见问题所参考的博客汇总

    工程是基于64位的 1 Error 26 error C2491: 'HUDManager::_viewport' : definition of dllimport static data memb ...

  4. 使用JQuery实现图片轮播效果

    [效果如图] [原理简述] 这里大概说一下整个流程: 1,将除了第一张以外的图片全部隐藏, 2,获取第一张图片的alt信息显示在信息栏,并添加点击事件 3,为4个按钮添加点击侦听,点击相应的按钮,用f ...

  5. HDU-1709 The Balance(生成函数)

    题意 给$n$个数,有哪些属于$1$到$n$个数字总和$sum$的数是通过该集合任意子集之间的加减运算无法得到的. 思路 对每个数构造$x^{-a[i]}+1+x^{a[i]}$,为了避免负幂次可以将 ...

  6. BUAA-OO-电梯调度

    BUAA-OO-电梯调度 1.设计策略 需求分析 设计一个系统,使其可以根据乘客的当前楼层和目的楼层,为乘客分配电梯资源并运送其至目的楼层. 自顶向下 根据需求,可以将整个系统分成三个部分: 处理乘客 ...

  7. asp.net webapi 获取报文体的问题

    用这种方法: var data=await Request.Content.ReadAsStringAsync(); 一般都无法获取到内容.原因是内部的流对象已经到了最后面.要获取到里面的需要把流的位 ...

  8. Mysql5.7数据导出提示--secure-file-priv选项问题的解决方法

    mysql可使用into outfile参数把表中的数据到处到csv,示例如下: select user_id from weibo_comment into outfile '/home/dazha ...

  9. web前端效率提升之禁用缓存-遁地龙卷风

    1.使用场景 我用的是Chrome,Ctrl+F5并不是在任何时候都能清楚缓存,这样很影响效率,下面的方式可以在开发者工具打开的使用禁止浏览器缓存任何资源, 还是出现不及时更新的情况,就要考虑服务器是 ...

  10. LeetCode第二十三题-合并n个有序链表

    Merge k Sorted Lists 问题简介:合并k个已排序的链表并将其作为一个排序链表返回. 举例: 输入: [ 1->4->5, 1->3->4, 2->6 ] ...