Codeforces Round #849 (Div. 4) ABCDEFG1

https://codeforces.com/contest/1791

ABCDEG1全水题,直接上代码
F往下翻

A. Codeforces Checking

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        char c;
        cin>>c;
        string s="codeforces";
        bool flag=false;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]==c)
            {
                flag=true;
                break;
            }
        }
        if(flag==false) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

B. Following Directions

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        LL x=0,y=0;
        bool flag=false;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='U') y++;
            else if(s[i]=='D') y--;
            else if(s[i]=='L') x--;
            else x++;
            if(x==1&&y==1) flag=true;
        }
        if(flag==true) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C .Prepend and Append

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        LL len=s.size();
        LL sum=len;
        for(int i=0,j=len-1;i<j;i++,j--)
        {
            if(s[i]=='0'&&s[j]=='1') sum-=2;
            else if(s[i]=='1'&&s[j]=='0') sum-=2;
            else break;
        }
        cout<<sum<<endl;
    }
    return 0;
}

D. Distinct Split

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
LL a[N]={0},b[N]={0};
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        s=" "+s;
        LL len=s.size();
        map<char,LL> mp;
        a[0]=b[len]=0;
        for(int i=1;i<s.size();i++)
        {
            mp[s[i]]++;
            a[i]=a[i-1]+(mp[s[i]]==1?1:0);
        }
        mp.clear();
        for(int i=len-1;i>=1;i--)
        {
            mp[s[i]]++;
            b[i]=b[i+1]+(mp[s[i]]==1?1:0);
        }
        LL maxn=0;
        for(int i=1;i<s.size()-1;i++)
        {
            //cout<<a[i]<<" "<<b[i]<<endl;
            maxn=max(maxn,a[i]+b[i+1]);
        }
        cout<<maxn<<endl;
        mp.clear();
    }
    return 0;
}

E. Negatives and Positives

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
LL a[N]={0},b[N]={0};
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL fu=0,zero=0,zh=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]<0) fu++;
            else if(a[i]==0) zero++;
            else zh++;
        }
        LL sum=0;
        if(fu%2==0||zero!=0)
        {
            for(int i=1;i<=n;i++)
                sum+=abs(a[i]);
            cout<<sum<<endl;
        }
        else
        {
            LL minn=abs(a[1]);
            for(int i=1;i<=n;i++)
            {
                minn=min(abs(a[i]),minn);
                sum+=abs(a[i]);
            }
            //cout<<sum<<" "<<minn<<endl;
            cout<<sum-2*minn<<endl;
        }
    }
    return 0;
}

G1. Teleporters (Easy Version)

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
LL a[N]={0},b[N]={0};
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            b[i]=i+a[i];
        }
        sort(b+1,b+1+n);
        LL sum=0;
        for(int i=1;i<=n;i++)
        {
            if(m>=b[i]) m-=b[i],sum++;
            else break;
        }
        cout<<sum<<endl;
    }
    return 0;
}

补题:
谁能想到我的F竟然被hack了,傻狗爆哭,还是少写点究极暴力[囧]

F. Range Update Point Query

https://codeforces.com/contest/1791/problem/F

题目大意:

给定一个数组a,q个更新,2种查询状态:
1 l r ————l≤i≤r中的所有数字,将ai值更新为ai每个位置上的数的总和。 
2 x ————输出a[x]。
input 
3
5 8
1 420 69 1434 2023
1 2 3
2 2
2 3
2 4
1 2 5
2 1
2 3
2 5
2 3
9999 1000
1 1 2
2 1
2 2
1 1
1
2 1
output 
6
15
1434
1
6
7
36
1
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4010;
const double PI=3.1415926535;
#define endl '\n'
LL solve(LL x)//位数求和
{
    LL sum=0;
    while(x)
    {
        sum+=x%10;
        x/=10;
    }
    return sum;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,q;
        cin>>n>>q;
        vector<LL> a(n+1);
        set<LL> st;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]>=10) st.insert(i);//大于等于10,一旦被指定,则需要更改,标记位置
        }
        while(q--)
        {
            LL op;
            cin>>op;
            LL x,y;
            if(op==1)
            {
                cin>>x>>y;
                while(!st.empty())
                {
                    auto it=st.lower_bound(x);
                    if(*it>y||it==st.end()) break;
                    x=(*it)+1;
                    a[*it]=solve(a[*it]);
                    if(a[*it]<=9) st.erase(it);
                }
            }
            else
            {
                cin>>x;
                cout<<a[x]<<endl;
            }
        }
    }
    return 0;
}
posted @ 2023-02-22 15:28  Vijurria  阅读(81)  评论(0编辑  收藏  举报