首页 > 其他分享 >CodeForces 1415D XOR-gun

CodeForces 1415D XOR-gun

时间:2023-01-27 16:11:07浏览次数:60  
标签:typedef XOR txdy int 1415D CodeForces long ans define

洛谷传送门

CF 传送门

纯纯的诈骗。

下文令 \(f(x)\) 为 \(x\) 最高位使得这一位为 \(1\)。考虑若存在 \(i \in [1,n-2]\) 使得 \(f(a_i) = f(a_{i+1}) = f(a_{i+2})\),那么可以合并 \(a_{i+1}\) 和 \(a_{i+2}\),这样最高位被消了,因此一定 \(< a_i\)。因此答案为 \(1\)。

若不存在,则 \(n \le 60\)。爱怎么搞怎么搞。

code
/*

p_b_p_b txdy
AThousandSuns txdy
Wu_Ren txdy
Appleblue17 txdy

*/

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 100100;

ll n, a[maxn];

void solve() {
	scanf("%lld", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= n - 2; ++i) {
		if (__lg(a[i]) == __lg(a[i + 1]) && __lg(a[i + 1]) == __lg(a[i + 2])) {
			puts("1");
			return;
		}
	}
	for (int i = 1; i <= n; ++i) {
		a[i] ^= a[i - 1];
	}
	int ans = 2e9;
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
			for (int k = j + 1; k <= n; ++k) {
				if ((a[j] ^ a[i - 1]) > (a[k] ^ a[j])) {
					ans = min(ans, k - i - 1);
				}
			}
		}
	}
	printf("%d\n", ans > 1e9 ? -1 : ans);
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

标签:typedef,XOR,txdy,int,1415D,CodeForces,long,ans,define
From: https://www.cnblogs.com/zltzlt-blog/p/17068969.html

相关文章

  • Educational Codeforces Round 1
    A.TrickySum题意:给一个n,求1到n的运算,如果不是2的次方就加,否则减思路:由于n有1e9,直接暴力扫过去肯定要寄所以先$n*(n+1)/2$来算出1到n的和再减去2倍的2......
  • 1.27 vp Codeforces Round #845 (Div. 2) and ByteRace 2023
    A-EverybodyLikesGoodArrays!题意(构造)给出序列a,需要使a中元素以相邻元素奇偶性不同排列,你可以进行若干操作:将一对相邻奇偶性相同的元素相乘问最少需要多少次操作......
  • Codeforces 708 A-E1题解
    A.Meximization这道题问给一些数,如何让前缀的mex之和最大,那么首先,我们要抬mex的话肯定是要把前面都铺垫完的,所以在i位置确定的时候,i+1自然是越大越好,可以证明i+1的位......
  • Codeforces Round 846
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1780。执念就像是记错的二级结论一样可怕的东西。冥冥之中有一种结论错了的感觉,但总是觉......
  • Codeforces 44E Anfisa the Monkey
    https://codeforces.com/contest/44/problem/E高级又好像很低级的诈骗首先不难得到\(a\timesk>|s|\texttt{or}b\timesk<|s|\)无解。对于每一组考虑先填上\(a\)......
  • Codeforces Round #846 (Div. 2) E. Josuke and Complete Graph(数论分块)
    题意:给定一个区间[L,R],求其中任意两个数字的gcd的不同的种类总数。链接:https://codeforces.com/contest/1780/problem/E其中L<=1e9,1<=L<=R<=1e18。tips:本篇题解中除标......
  • vp CodeForces 合集
    由于这只蒟蒻 非常不想熬夜打CF 经常忘了要打CF,然后再加上能力很踹,于是就弱弱的来vpCF了。(我不会说我vp时用的是这个号)Contest1792 ......
  • Educational Codeforces Round 142 (Rated for Div. 2)
    题目链接A核心思路水题,想清楚代价就好了。//Problem:A.GamingForces//Contest:Codeforces-EducationalCodeforcesRound142(RatedforDiv.2)//URL:htt......
  • Codeforces Round #846 (Div. 2)
    E.JosukeandCompleteGraph题目抽象为求\(\gcd(i,j)\)有多少种\((i\neqj,i\in[l,r],j\in[l,r])\),如:当\(l=2,r=4\)时,\(\gcd(2,4)=2\),\(\gcd(2,3)=\gcd(3,4)=1\)......
  • Educational Codeforces Round 142 (Rated for Div. 2)
    E.DivisorsandTable\(m=m_1\cdotm_2\)找\(m\)的所有因子,记为数组\(x\)。对于\(x_i\),找它的最大的小于等于\(n\)的因子\(y\),那么\(x_i\)的贡献为\(\frac{x......