time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard inputoutput: standard output Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since S…
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved…
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play a computer game where you have to breed some magical creatures. Initially, they have k creatures numbered from 1 to k. Creatures have n different cha…
https://codeforces.com/contest/1330/problem/D 给出d,m, 找到一个a数组,满足以下要求: a数组的长度为n,n≥1; 1≤a1<a2<⋯<an≤d: 定义一个数组b:b1=a1, ∀i>1,bi=bi−1⊕ai ,并且b1<b2<⋯<bn−1<bn: 求满足条件的a数组的个数并模m: 人话:求一个a数组满足递增,并且异或前缀和也递增 ,求出a数组个数mod m. 太菜了,不会,看了很多题解才会的,这里总结一下:…
题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) struct node{ long long num, lazy; } tree[ << ]; st…
题解: 首先,我们可以用 dfsdfsdfs 在 O(n)O(n)O(n) 的时间复杂度求出初始状态每个点的权值. 不难发现,一个叶子节点权值的取反会导致根节点的权值取反当且仅当从该叶子节点到根节点这一条链上的每个点的权值都被取反(都被影响到).而这4种逻辑运算中,NOTNOTNOT 和 XORXORXOR 是最简单的,即只要2个儿子中的一个儿子的值被取反,该点的值就会被取反.但 ANDANDAND 和 OROROR 存在只修改一个儿子时不会对该点的权值产生影响的情况,这就需要我们进行一下特判.…
传送门 题目大意: 输入给出一串位运算,输出一个步数小于等于5的方案,正确即可,不唯一. 题目分析: 英文题的理解真的是各种误差,从头到尾都以为解是唯一的. 根据位运算的性质可以知道: 一连串的位运算最终都可以用三个位运算代替(&|^). 那么仅需对每一位的情况进行讨论,某一位: 必须变为1 (|1) 必须变为0 (&0) 必须01颠倒(^1) 最后输出3种位运算即可(输出三种最稳妥). code #include<bits/stdc++.h> using namespace…
题目链接:点击打开链接 Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the n…
题意: 求n个数中两两和的异或. 思路: 逐位考虑,第k位只需考虑0~k-1位,可通过&(2k+1-1)得到一组新数. 将新数排序,当两数和在[2k,2k+1)和[2k+1+2k,2k+2)之间时该位为1,又因为两数的最大和为2*(2k+1-1)=2k+2-2, 即当两数和在[2k,2k+1)和[2k+1+2k,2k+2-2]之间时该位为1. 对于每个数,找到和 大于等于2k 小于2k+1 大于等于2k+1+2k 的三个临界点(因为两数之和一定小于等于2k+2-2,所以第四个临界点可以忽略),…
Problem   Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem Description Input The first line contains one integer n (2≤n≤3⋅10^5) — the size of the array. The second line contains n integers a1,a2,…,an (0≤ai<2^…