codeforces round 959(A~C)

A

Petr, watching Sergey’s stream, came up with a matrix a a a, consisting of n n n rows and m m m columns (the number in the i i i-th row and j j j-th column is denoted as a i , j a_{i, j} ai,j), which contains all integers from 1 1 1 to n ⋅ m n \cdot m nm. But he didn’t like the arrangement of the numbers, and now he wants to come up with a new matrix b b b, consisting of n n n rows and m m m columns, which will also contain all integers from 1 1 1 to n ⋅ m n \cdot m nm, such that for any 1 ≤ i ≤ n , 1 ≤ j ≤ m 1 \leq i \leq n, 1 \leq j \leq m 1in,1jm it holds that a i , j ≠ b i , j a_{i, j} \ne b_{i, j} ai,j=bi,j.

You are given the matrix a a a, construct any matrix b b b that meets Petr’s requirements, or determine that it is impossible.

Hurry up! Otherwise, he will donate all his money to the stream in search of an answer to his question.
Input

Each test consists of multiple test cases. The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers n n n and m m m ( 1 ≤ n , m ≤ 10 1 \leq n, m \leq 10 1n,m10) — the number of rows and columns of matrix a a a.

The next n n n lines contain m m m integers each, describing matrix a a a. The i i i-th of these lines contains the elements of matrix a i , 1 , a i , 2 , … , a i , m a_{i, 1}, a_{i, 2}, \ldots, a_{i, m} ai,1,ai,2,,ai,m.

It is guaranteed that all numbers in matrix a a a are distinct and 1 ≤ a i , j ≤ n ⋅ m 1 \leq a_{i, j} \leq n \cdot m 1ai,jnm.

It is guaranteed that the sum of n ⋅ m n \cdot m nm over all test cases does not exceed 5 ⋅ 1 0 4 5 \cdot 10^4 5104.

**这道题我唐的一批,交了好多发错的,先来欣赏一下我的错误吧 **
我直接把1~n做了个标记,然后从大到小输出满足(num[k]!=1&&a[i][j]!=k)
就输出了,听起来好像问题不大,不就换个顺序嘛,但是其实非也。
例如3124如果按我的方法,就是先美美输出123,但是发现,4输不出来了,WA’
后来我又用了另一种方法,就是直接给所给数换序

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int num[1001];
 
int main() {
	int t, n, m, sign;
	int a[11][11];
	cin >> t;
	while (t--) {
		cin >> n >> m;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				cin >> a[i][j];
		if (n == 1 && m == 1) {
			cout << -1 << endl;
			continue;
		} else if (n == 1) {
			for (int i = 1; i < m; i++)
				printf("%d ", a[0][i]);
			cout << a[0][0] << endl;
		} else if (m == 1) {
			for (int j = 1; j < n; j++)
				cout << a[j][0] << endl;
			cout << a[0][0] << endl;
		} else {
			for (int i = 0; i < n ; i++) {
 
				for (int j = 1; j < m; j++)
					cout << a[i][j] << ' ';
				cout << a[i][0];
				cout << endl;
			}
		}
	}
	return 0;
}

要注意判断n=m=1时输出-1

B

Vova really loves the XOR operation (denoted as ⊕ \oplus ). Recently, when he was going to sleep, he came up with a fun game.

At the beginning of the game, Vova chooses two binary sequences s s s and t t t of length n n n and gives them to Vanya. A binary sequence is a sequence consisting only of the numbers 0 0 0 and 1 1 1. Vanya can choose integers l , r l, r l,r such that 1 ≤ l ≤ r ≤ n 1 \leq l \leq r \leq n 1lrn, and for all l ≤ i ≤ r l \leq i \leq r lir simultaneously replace s i s_i si with s i ⊕ s i − l + 1 s_i \oplus s_{i - l + 1} sisil+1, where s i s_i si is the i i i-th element of the sequence s s s.

In order for the game to be interesting, there must be a possibility to win. Vanya wins if, with an unlimited number of actions, he can obtain the sequence t t t from the sequence s s s. Determine if the game will be interesting for the sequences s s s and t t t.
Input

Each test consists of multiple test cases. The first line contains an integer q q q ( 1 ≤ q ≤ 1 0 4 1 \le q \le 10^{4} 1q104) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \leq n \leq 2 \cdot 10^5 1n2105) — the length of the sequences s s s and t t t.

The second line of each test case contains a binary sequence s s s of length n n n.

The third line of each test case contains a binary sequence t t t of length n n n.

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.
Output

For each test case, output “Yes” if the game will be interesting, otherwise output “No”.

You can output each letter in any case (for example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as a positive answer).
6
1
0
1
7
0110100
0110100
9
100101010
101111110
4
0011
1011
4
0100
0001
8
10110111
01100000
NO
YES
YES
NO
YES
YES
这个题需要一些思考,自己去试一试样例,然后就发现其实整个异或就是全是0,然后就是如果第一个数是1,那么所有的都能直接变成1。
然后看第二个给的NO的样例
其实就是前面0011的00没办法改变,所以其实就是找第一个出现的1,如果给的数组比所需数组早,就可以,这里注意如果没有出现1,就把位置设成最大的数(我设成最小的,结果特判错了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a1[200005],a2[200005];
 
int main() {
	int n, t, s1, s2;
	cin >> t;
	while (t--) {
		cin >> n;
		s1 = s2 = 5000000;
		for (int i = 0; i < n; i++)
			scanf("%1d", &a1[i]);
		for (int i = 0; i < n; i++)
			if (a1[i]) {
				s1 = i;
				break;
			}
		for (int i = 0; i < n; i++)
			scanf("%1d", &a2[i]);
		for (int i = 0; i < n; i++)
			if (a2[i]) {
				s2 = i;
				break;
			}
	
			
		if (s1 <= s2) {
			cout << "YES" << endl;
 
		} else
			cout << "NO" << endl;
	}
	return 0;
}

C

Yaroslav is playing a computer game, and at one of the levels, he encountered n n n mushrooms arranged in a row. Each mushroom has its own level of toxicity; the i i i-th mushroom from the beginning has a toxicity level of a i a_i ai. Yaroslav can choose two integers 1 ≤ l ≤ r ≤ n 1 \le l \le r \le n 1lrn, and then his character will take turns from left to right to eat mushrooms from this subsegment one by one, i.e., the mushrooms with numbers l , l + 1 , l + 2 , … , r l, l+1, l+2, \ldots, r l,l+1,l+2,,r.

The character has a toxicity level g g g, initially equal to 0 0 0. The computer game is defined by the number x x x — the maximum toxicity level at any given time. When eating a mushroom with toxicity level k k k, the following happens:

  1. The toxicity level of the character is increased by k k k.
  2. If g ≤ x g \leq x gx, the process continues; otherwise, g g g becomes zero and the process continues.

Yaroslav became interested in how many ways there are to choose the values of l l l and r r r such that the final value of g g g is not zero. Help Yaroslav find this number!
Input

Each test consists of multiple test cases. The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^{4} 1t104) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers n n n, x x x ( 1 ≤ n ≤ 2 ⋅ 1 0 5 , 1 ≤ x ≤ 1 0 9 1 \leq n \leq 2 \cdot 10^5, 1 \le x \le 10^9 1n2105,1x109) — the number of mushrooms and the maximum toxicity level.

The second line of each test case contains n n n numbers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 1 \leq a_i \leq 10^9 1ai109).

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.
Output

For each test case, output a single number — the number of subsegments such that the final value of g g g will not be zero.
这道题,是dp+二分+前缀和
首先我们可以发现,他的和从0开始(a),过一会又归0了(b),其中有sum[b]-sum[a-1]=x所以其实我们可以用dp把dp[a]和dp[b]联系起来,因为到b以后相当于另1一个开始,即dp[a]=dp[b]+b-a
其中dp[i]表示以i为左端点的情况数之和,在a到b之间有b-a的情况当然可以算到a为节点里面的,而且我们这个前面的状态是以后面为转移的,所以从后往前进行dp。
这就是大体思路
我们将a的前缀和存起来,用二分找sum[a-1]+x在哪里(也就是b的位置)
这里吧二分函数再复习一下
lower_bound(a+1,a+1+n,v);返回位置 a+1~a+1+n 中v的位置 若没有,则返回它应该所在的位置 ,若多个则返回第一个的位置
这个是小于等于的位置
upper_bound(a+1,a+1+n,v);返回位置 a+1~a+1+n 中v的位置加1 若没有,则返回它应该所在的位置 ,若多个则返回最后一个的位置加1;
这个是大于的位置
要好好理解这个它应该所在的位置
就像你就算给1,2,3给一个4他虽然只有3个下标,但是会返回4,因为他应该在第四个下标的位置
这里还有要注意,就是其实这个sum[a-1]+b的点不能做下一个点,因为是0嘛,所以要在这个点的下一个,所以用upper_bound
下面是代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200005
ll a[N], sum[N], dp[N];

int main() {
  ll x, n, t, ans = 0, tmp;
  cin >> t;
  while (t--) {
  	memset(dp, 0, sizeof(dp));
  	ans = 0;
  	cin >> n >> x;
  	for (int i = 1; i <= n; i++) {
  		cin >> a[i];
  		sum[i] = sum[i - 1] + a[i];
  	}
  	for (int i = n; i >= 1; i--) {
  		// if(sum[i]+x>=sum[n]){
  		// 	dp[i]=n-i+1;
  		// 	continue;
  		// }
  		tmp = upper_bound(sum + 1, sum + 1 + n, sum[i - 1] + x) - sum;
  		dp[i] = tmp - i  + dp[tmp + 1];
  		// cout << i << ' ' << tmp << ' ' << dp[i] << endl;
  	}
  	for (int i = 1; i <= n; i++)
  		ans += dp[i];
  	cout << ans << endl;
  }
  return 0;
}

结语

第一次打codeforces 虽然不简单但好像也没有很难,所以以后还想打,希望可以继续加油

### Codeforces Round 995 Problems and Solutions For a participant named Pasha who aims to solve all problems within the duration of a coding competition, it is important to calculate the minimum time required for submitting all solutions correctly[^1]. This involves understanding problem constraints, expected outputs, precision requirements, and specific conditions related to array sizes or permutations. #### Problem A: Minimal Submission Time Calculation Given multiple tasks with varying complexities, one must determine the least amount of time needed to complete these submissions successfully. The algorithm should consider both solving times and submission processes efficiently so as not to exceed contest limits while ensuring accuracy in responses provided by participants like K1o0n whose answers need validation through tests involving pairs of integers \(a_i\) and \(b_i\)[^2]. #### Problem B: Precision Output Requirements When dealing with numerical computations where exactness matters greatly—such as floating-point operations—it's crucial that any computed result has an absolute error no more significant than \(10^{-9}\). Such stringent tolerances ensure high fidelity across different platforms running similar algorithms but potentially yielding slightly varied results due to hardware differences during execution phases[^3]. #### Problem C: Permutation Construction Constraints Constructing valid sequences under given parameters requires adherence to strict rules about element counts (\(n\)), alongside additional integer values (\(m,k\)) defining further restrictions on how elements may appear inside said sequence structures without violating imposed boundaries set forth at initialization stages when specifying permissible ranges for individual components involved[^4]. #### Problem D: Array Size Validation Logic Validating whether certain properties hold true over collections necessitates careful examination against predefined criteria regarding their dimensions. For instance, identifying configurations containing exactly two subarrays meeting specified length thresholds would constitute invalid cases according to some problem statements found within competitive programming challenges hosted online[^5]. ```cpp // Example code snippet demonstrating basic logic checks for validating array sizes. #include <iostream> using namespace std; bool validateArraySizes(int* arr, int size) { int count = 0; for (int i = 0; i < size - 1; ++i) { if ((arr[i] >= 2 && arr[i + 1] >= 2)) count++; } return count != 2; } int main() { int exampleArr[] = { /* ... */ }; cout << boolalpha << validateArraySizes(exampleArr, sizeof(exampleArr)/sizeof(*exampleArr)); } ``` --related questions-- 1. How do we optimize the calculation process for determining minimal submission times? 2. What methods exist to improve computational efficiency when working towards achieving precise numeric outcomes? 3. Can you provide examples illustrating common pitfalls encountered during permutation construction based on defined parameter sets? 4. In what ways can logical operators assist programmers in verifying complex data structure attributes accurately?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值