Codeforces Round #752 (Div. 2) A B C D

Keywords: C Back-end CodeForces

Codeforces Round #752 (Div. 2)

Record high!!

A. Era

Idea: at first, I thought it was to find a maximum subscript, and then output the maximum minus the maximum subscript. Later, I dropped this idea with the data 1 1 5 1 6 hack, and it was obvious that as long as I enumerated it, I saved the largest memory a [ i ] − i d x a[i]-idx a[i] − idx.

  • Reference code:
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int a[N];
#define snow ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll=long long ;
void solve(){
    int n;
    cin>>n;
    int MA=-2e9;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        MA=max(MA,a[i]-i);
    }
    cout<<max(0,MA)<<endl;
}
int main(){
    snow;
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

B. XOR Specia-LIS-t

Train of thought: because all the last segments are required L I S LIS LIS x o r xor The xor value is 0, so obviously if n n The number of n is even. We can pair every two numbers separately, and finally form an even pair x o r xor xor values are all 1, then even pairs x o r xor The final value of xor must be 0 0 0, if n n If the number of n is odd, then we just need to a a A if two adjacent numbers are found in the array and the sequence formed by the combination is a non rising sequence, then these two numbers are composed h h h value is still 1 1 1, then return to the above n n n is an even number.

  • Reference code:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
#define snow ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll=long long ;
void solve(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n%2==0){
        cout<<"YES"<<endl;
        return ;
    }
    else{
        int success=0;
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){success=1;break;}
        }
        if(success)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
int main(){
    snow;
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

C. Di-visible Confusion

Train of thought: I think in the direction of the sieve method and put the array a a a enumerate once, if the current a [ i ] a[i] a[i] can be i d x + 1 , i d x , i d x − 1...1 + 1 idx+1,idx,idx-1 ... 1+1 Screen out any one of idx+1, IDX, idx − 1... 1 + 1, that is a [ i ]   m o d   i d x + 1 ! = 0 a[i]\bmod idx+1!=0 a[i]modidx+1!=0 means that this number can be screened out. Why can it be its subscript and any position in front of it? Why not judge after its subscript? prove: 1 : 1: 1: If the following number is sieved out, all numbers after the sieved number are subscripted and subtracted 1 1 1 will not affect the previous number, so there is no need to judge the subsequent subscript of the previous number. 2 : 2: 2: Why judge it and its leading subscript? Because if the number in front of this number is sieved out, it may be in any position in front, and if it is sieved out in any position in front, it means that this number can be sieved out r e m o v e remove remove i i in a a a. So it's enumeration, which seems to be O ( n 2 ) O(n^2) O(n2), but if you think about it, you will find that this number is as long as m o d mod mod i d x + 1 ! = 0 idx+1 !=0 idx+1!=0 can be used directly b r e a k break break off, and this condition is very weak and easy to implement b r e a k break break. For example, if the number is very large, yes 1 e 5 1e5 1e5 level, so what number can be achieved at the same time m o d mod mod 1 e 5 and 1 e 5 − 1 and 1 e 5 − 2 = 0 ? 1E5 and 1e5-1 and 1e5-2=0? 1e5 and 1e5 − 1 and 1e5 − 2 = 0? Or another one 1 e 5 − 3 ? 1e5-3? 1e5−3? So the conditions are very weak, far from reaching O ( n 2 ) O(n^2) O(n2).

  • Reference code:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
#define snow ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll=long long ;
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        bool success=false;
        for(int j=i;j>=1;j--){
            int x=j+1;
            if(a[i]%x!=0){
                success=true;
                break;
            }
        }
        if(success==false){
            cout<<"NO"<<endl;
            return ;
        }
    }
    cout<<"YES"<<endl;
    return ;
}
int main(){
    snow;
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

D. Moderate Modular Mode

Idea: discuss in three situations, 1 : X = = Y 1: X==Y 1:X==Y, so obviously we take n n n is X X X o r or or Y Y Y is OK, because n n n m o d mod mod X = = X== X== Y Y Y m o d mod mod n = = 0 n==0 n==0. 2 : X < Y 2:X<Y 2: X < y, we just need to take n = X ∗ Y + Y n=X*Y+Y n=X * Y+Y can also be very good. 3 : X > Y 3:X>Y 3: X > y, many people directly let n = ( X + Y ) / 2 n=(X+Y)/2 n=(X+Y)/2, but it is obviously wrong h a c k hack hack data 4 4 4 and 18 18 18, if n = ( X + Y ) / 2 n=(X+Y)/2 n=(X+Y)/2, then n = 11 n=11 n=11 is obviously wrong and easy to find if X = 16 X=16 X=16 and Y = 18 Y=18 If Y=18, take n = ( X + Y ) / 2 = 17 n=(X+Y)/2=17 n=(X+Y)/2=17 is obviously right, so the correct way is to replace the former X X X is magnified in multiples to no more than Y Y The maximum form of Y is enough, so the correct way is to take n = Y − Y n=Y-Y n=Y−Y m o d mod mod X / 2 X/2 X/2 is enough.

  • Reference code:
#include<bits/stdc++.h>
using namespace std;
#define snow ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll=long long ;
void solve(){
    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(){
    snow;
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Posted by jaybeeb on Sat, 30 Oct 2021 11:24:42 -0700