Codeforces Round #590 (Div. 3)(ef待补

Posted h404nofound

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #590 (Div. 3)(ef待补相关的知识,希望对你有一定的参考价值。

https://codeforces.com/contest/1234/problem/A

A. Equalize Prices Again

技术图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main()
 5     int n,a;
 6     int t;
 7     cin>>t;
 8     ll sum = 0,ans;
 9     while(t--)
10         cin>>n;sum = 0;
11         for(int i = 0;i < n;++i)
12             cin>>a;sum+=a;
13         
14         ans = sum/n;
15         if(sum%n)ans+=1;
16         cout<<ans<<endl;
17     
18 
AC代码

https://codeforces.com/contest/1234/problem/B1

B1. Social Network (easy version)

https://codeforces.com/contest/1234/problem/B2

B2. Social Network (hard version)

技术图片
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a;
int n ,k ,now=0,fi=0;
vector<ll>s;
map<ll,int>mp;
int main()
    cin>>n>>k;
    for(int i = 0;i < n;++i)
        cin>>a;
        if(mp[a]==0)
                mp[a]=1;s.push_back(a);
            if(now<k)
                now++;
            
            else if(now==k)
                mp[s[fi]]=0;fi++;
            
        
    
    cout<<now<<endl;
    int l =s.size()-1;
    int cnt=0;
    while(cnt<now&&l>=0)
        if(mp[s[l]])cnt++,cout<<s[l]<<" ";
        l--;
    
    cout<<endl;
 
    return 0;
AC代码

https://codeforces.com/contest/1234/problem/C

C. Pipes

旋转一遍发现前两种其实是不同方向摆放的一种管道,后四个同理,也就是只有两个管道,一个是直流另一个会变向,然后问题就很简单了。

技术图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4  
 5 int main()
 6     int t,n;
 7     cin>>t;
 8     while(t--)
 9         cin>>n;
10         string a[3];cin>>a[0]>>a[1];
11         int now=0,flag =1;
12         for(int i = 0;i <n;++i)
13             if(a[now][i]==1||a[now][i]==2)continue;
14             else
15                now=1-now;
16                if(a[now][i]==1||a[now][i]==2)
17                 flag=0;break;
18                
19             
20         
21         if(flag==0||now==0)cout<<"no"<<endl;
22         else cout<<"yes"<<endl;
23     
24     return 0;
25 
AC代码

https://codeforces.com/contest/1234/problem/D

D. Distinct Characters Queries

用线段树维护不同字母的个数orz学到了新东西,待会再看看set的做法?

技术图片
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
int a[N],ans[30];
int tree[4*N][26];
void build(int l,int r,int rt)
    if(l==r)tree[rt][a[l]]++;return ;
    int mid=(l+r)/2;
    build(l,mid,rt*2);
    build(mid+1,r,rt*2+1);
    for(int i = 0;i < 26;++i)tree[rt][i]=tree[rt*2][i]+tree[rt*2+1][i];

void f5(int l,int r,int rt,int x,int p,int f)
    if(l==r)tree[rt][p]--;tree[rt][f]++;return ;
    int mid=(l+r)>>1;
    if(x<=mid)f5(l,mid,rt<<1,x,p,f);
    else f5(mid+1,r,rt<<1|1,x,p,f);
    for(int i = 0;i < 26;++i)tree[rt][i]=tree[rt<<1][i]+tree[rt<<1|1][i];

void query(int l,int r,int rt,int ll,int rr)
    if(r<=rr&&l>=ll)
        for(int i = 0;i < 26;++i)ans[i]+=tree[rt][i]; return ;
    
    int mid=(l+r)>>1;
    if(ll<=mid)query(l,mid,rt<<1,ll,rr);
    if(rr>mid)query(mid+1,r,rt<<1|1,ll,rr);

int main()

    ios::sync_with_stdio(0);
    string s;cin>>s;int n = s.size();
    for(int i = 0;i < n;++i)a[i+1]=s[i]-a;
    build(1,n,1);
    int m;cin>>m;
    while(m--)
        int flag,x,l,r;char c;cin>>flag;
        if(flag==1)
            cin>>x>>c;
            f5(1,n,1,x,s[x-1]-a,c-a);
            s[x-1]=c;
        
        else
            cin>>l>>r;memset(ans,0,sizeof(ans));
            query(1,n,1,l,r);
            int tot=0;
            for(int i = 0;i < 26;++i)if(ans[i])tot++;
            cout<<tot<<endl;
        
    
    return 0;
AC代码

 

以上是关于Codeforces Round #590 (Div. 3)(ef待补的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #590 (Div. 3)

Codeforces Round #590 (Div. 3) C. Pipes

Codeforces Round #590 (Div. 3)

Codeforces Round #590 (Div. 3)

CodeForces Round #590 (Div 3)

Codeforces Round #590 (Div. 3)