Codeforces Round #752 (Div. 2)

这篇博客探讨了三个关于序列操作的问题:如何通过插入操作使序列元素小于等于其位置,如何分割序列使XOR结果为0,以及如何消除不被相邻数整除的元素。通过模拟和数学分析,博主提供了简洁的解决方案,并展示了在不同场景下如何应用这些策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Era

Shohag has an integer sequence a1,a2,…,an. He can perform the following operation any number of times (possibly, zero):

Select any positive integer k (it can be different in different operations).
Choose any position in the sequence (possibly the beginning or end of the sequence, or in between any two elements) and insert k into the sequence at this position.
This way, the sequence a changes, and the next operation is performed on this changed sequence.
For example, if a=[3,3,4] and he selects k=2, then after the operation he can obtain one of the sequences [2–,3,3,4], [3,2–,3,4], [3,3,2–,4], or [3,3,4,2–].

Shohag wants this sequence to satisfy the following condition: for each 1≤i≤|a|, ai≤i. Here, |a| denotes the size of a.

Help him to find the minimum number of operations that he has to perform to achieve this goal. We can show that under the constraints of the problem it’s always possible to achieve this goal in a finite number of operations.

AC

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define psi pair<string, int>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ld long double
const int N = 1E2 + 7;
#define INF ~0ULL
int t;
int n;
int arr[N];

int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> arr[i];
        }
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            ans = max (arr[i]-i,ans);
        }
        cout<<ans<<endl;

    }
}

B. XOR Specia-LIS-t

YouKn0wWho has an integer sequence a1,a2,…an. Now he will split the sequence a into one or more consecutive subarrays so that each element of a belongs to exactly one subarray. Let k be the number of resulting subarrays, and h1,h2,…,hk be the lengths of the longest increasing subsequences of corresponding subarrays.

For example, if we split [2,5,3,1,4,3,2,2,5,1] into [2,5,3,1,4], [3,2,2,5], [1], then h=[3,2,1].

YouKn0wWho wonders if it is possible to split the sequence a in such a way that the bitwise XOR of h1,h2,…,hk is equal to 0. You have to tell whether it is possible.

The longest increasing subsequence (LIS) of a sequence b1,b2,…,bm is the longest sequence of valid indices i1,i2,…,ik such that i1<i2<…<ik and bi1<bi2<…<bik. For example, the LIS of [2,5,3,3,5] is [2,3,5], which has length 3.

An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

思路

偶数直接过
奇数找一对凑成偶数
如果连二都凑不出来,只能说明原数组的最长
递增子序列为n,奇数个的xor结果不会为0

AC

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define psi pair<string, int>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ld long double
const int N = 1E5 + 7;
#define INF ~0ULL
int t;
int n;
int arr[N];
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> arr[i];
        }
        bool flag = 0;
        if (n % 2 == 0)
        {
            cout << "YES" << endl;
        }
        else
        {
            for (int i = 2; i <= n; i++)
            {
                if (arr[i] <= arr[i - 1])
                {
                    flag = 1;
                    break;
                }
            }
            if (flag)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}

C. Di-visible Confusion

YouKn0wWho has an integer sequence a1,a2,…,an. He will perform the following operation until the sequence becomes empty: select an index i such that 1≤i≤|a| and ai is not divisible by (i+1), and erase this element from the sequence. Here |a| is the length of sequence a at the moment of operation. Note that the sequence a changes and the next operation is performed on this changed sequence.

For example, if a=[3,5,4,5], then he can select i=2, because a2=5 is not divisible by i+1=3. After this operation the sequence is [3,4,5].

Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.

思路

模拟

AC

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define psi pair<string, int>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ld long double
const int N = 1E5 + 7;
#define INF ~0ULL
int t;
int n;
int arr[N];

bool cc()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 1; i <= n; i++)
    {
        bool f = 1;
        for (int j = i; j >= 1; j--)
        {
            if (arr[i] % (j + 1))
            {
                f = 0;
                break;
            }
        }
        if (f)
            return false;
    }
    return true;
}
int main()
{
    cin >> t;
    while (t--)
    {
        if (cc()) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

D. Moderate Modular Mode

YouKn0wWho has two even integers x and y. Help him to find an integer n such that 1≤n≤2⋅1018 and nmodx=ymodn. Here, amodb denotes the remainder of a after division by b. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

思路

找个值使得n%x,y%n
如果x=y n=x
x>y 凑成x=y (mody) ans = x*y+y
x<y y - y % x / 2

AC

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void cc()
{
    ll a, b;
    cin >> a >> b;
    if (a > b)
    {
        ll res;
        res = a * b + b;
        cout << res << endl;
    }
    else if (a == b)
    {
        cout << a << endl;
    }
    else
    {
        cout << b - b % a / 2 << endl;
    }
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cc();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.0-0.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值