Educational Codeforces Round 59 (Rated for Div. 2)

A. Digits Sequence Dividing

题解:因为每个数字都是[1,9]那么直接分成两部分即可 特判n=2的情况

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=3e5+10;
const double eps=1e-8;
#define ll long long
using namespace std;
struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}

char str[MAXN];
int main(){
    int _=read();
    while(_--){
	int n;n=read();
	inc(i,1,n)scanf("%c",&str[i]);
	if(n==2&&str[1]>=str[2])printf("NO\n");
	else{
	    puts("YES");
	    printf("%d\n",2);
	    printf("%d ",str[1]-'0');
	    inc(i,2,n)printf("%d",str[i]-'0');
	    printf("\n");
	}
    }
}

B. Digital root

题解:打表即可

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 100005
#define nm 1000005
#define pi 3.1415926535897931
const ll inf=998244353;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 
 




ll n,k;

int main(){
    int _=read();while(_--){
	n=read();k=read();
	printf("%lld\n",9*(n-1)+k);
    }
    return 0;
}

C. Brutality

题解: 分段考虑 排序取前k个

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=3e5+10;
const double eps=1e-8;
#define ll long long
using namespace std;
struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}

vector<int>vec;
char str[MAXN];int a[MAXN];
bool cmp(int t1,int t2){return t1>t2;}
int main(){
    int n=read();int k=read();
    inc(i,1,n)a[i]=read();
    scanf("%s",str+1);
    vec.pb(a[1]);
    ll ans=0;
    inc(i,2,n){
	if(str[i]==str[i-1])vec.pb(a[i]);
	else{
	    sort(vec.begin(),vec.end(),cmp);
	    int t1=vec.size();int t2=min(k,t1);
	    for(int j=0;j<t2;j++)ans+=vec[j];
	    vec.clear();
	    vec.pb(a[i]);
	}
    }
    sort(vec.begin(),vec.end(),cmp);
    int t1=vec.size();int t2=min(k,t1);
    for(int j=0;j<t2;j++)ans+=vec[j];
    vec.clear();
    printf("%lld\n",ans);
}

 D. Compression

题解: bitset暴力莽   是有不需要bitset的做法的

题解:https://www.cnblogs.com/greenty1208/p/10332400.html

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 5205
#define nm 1000005
#define pi 3.1415926535897931
const ll inf=998244353;
using namespace std;
ll read(){
    char ch=getchar();
    while(!isdigit(ch)&&!('A'<=ch&&ch<='Z'))ch=getchar();
    if(isdigit(ch))return ch-'0';
    else return ch-'A'+10;
}
 
 



bitset<5201>a[NM],tmp;
int n,ans,cnt;

bool check(int t){
    int m=n/t-1;
    inc(i,0,m)
	inc(j,0,m){
	    int _t=a[i*t+1][j*t+1];
	    inc(k,2,t)if(a[i*t+1][j*t+k]!=_t)return false;
	}
    inc(i,0,m){
	inc(j,2,t){
	    tmp=a[i*t+1]^a[i*t+j];
	    if(tmp.count())return false;
	}
    }
    return true;
}

int main(){
    scanf("%d",&n);ans=1;cnt=n;
    inc(i,1,n){
	inc(j,1,n/4){
	    int t=read();
	    inc(k,0,3)if(t&succ(k))a[i].set(4*j-k);
	}
    }
    //inc(i,1,n){inc(j,1,n)printf("%d",(int)a[i][j]);putchar('\n');}
    for(int i=2;i*i<=cnt;i++)if(cnt%i==0){
	int j=i;
	for(;cnt%i==0;j*=i){
	    cnt/=i;
	    if(!check(j)){ans*=j/i;break;}
	    if(cnt%i){ans*=j;break;}
	}
	while(cnt%i==0)cnt/=i;
    }
    if(cnt>1)if(check(cnt))ans*=cnt;
    printf("%d\n",ans);
}

 E. Vasya and Binary String

题解:https://blog.csdn.net/qkoqhh/article/details/86681107

题解:https://www.cnblogs.com/greenty1208/p/10331195.html

F. 待补

G. G. Vasya and Maximum Profit

题解:长得像dp的数据结构题  

首先  确定这个表达式   S=a*(r-l+1)-(cl+.....+cr)-max(.....题目的那个式子) (没有md打不出公式)

          然后我们对这个式子做个变形  并令k=max(.....)

    S=a*r-C[r]-[a*(l-1)-C[l-1]]-k  C表示对于c数组求前缀和

    令b数组等于 b[i]=a*i-C[i]

           让S最大那么b[r]-b[l-1]差值最大  

           对于常数k我们怎么处理呢   有两种办法  对k最大值分治  然后求跨过这个位置两边的最大最小值  这个可以通过st表/线段树获得

    另外一种做法  就是对于每个位置的k的我们单调栈找出他能表示的范围(即最大值就是当前位置的区间)  然后对于每个区间st处理维护  b[r]-b[l-1]的最大值

场上qko大爷的做法  是第一种分治做的  他说他不会写数据结构(滑稽)

吐槽  这个人的st表写的真丑

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 300005
#define nm 1000005
#define pi 3.1415926535897931
const ll inf=998244353;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 
 



int n;
ll a,ans,d[NM],c[NM],pre[NM],suc[NM],mn[NM],smax[NM][20],smin[NM][20];
struct P{
    int i;ll t;
    bool operator<(const P&o)const{return t<o.t;}
}st[NM][20];

P query(int l,int r){
    int k=mn[r-l];
    return max(st[l][k],st[r-succ(k)+1][k]);
}

ll rmq(int l,int r){
    int k=mn[r-l];
    return max(smax[l][k],smax[r-succ(k)+1][k]);
}
ll _rmq(int l,int r){
    int k=mn[r-l];
    return min(smin[l][k],smin[r-succ(k)+1][k]);
}


void dfs(int x,int y){
    if(x==y){
	ans=max(ans,a-c[x]+c[x-1]);
	return;
    }
    P t=query(x,y-1);
    ans=max(ans,rmq(t.i+1,y)-_rmq(x-1,t.i)-sqr(t.t));
    dfs(x,t.i);dfs(t.i+1,y);
}

int main(){
    //freopen("data.in","r",stdin);
    n=read();a=read();
    inc(i,1,n)d[i]=read(),c[i]=read();
    inc(i,1,n)c[i]+=c[i-1];

    inc(i,1,n-1)st[i][0]=P{i,d[i+1]-d[i]};
    inc(i,1,n)smax[i][0]=smin[i][0]=a*i-c[i];
    inc(i,2,n)mn[i]=mn[i/2]+1;
    for(int j=1;succ(j)<n;j++)
	for(int i=0;i+succ(j)-1<n;i++)
	    st[i][j]=max(st[i][j-1],st[i+succ(j-1)][j-1]);
    for(int j=1;succ(j)<=n;j++)
	for(int i=0;i+succ(j)-1<=n;i++)
	    smax[i][j]=max(smax[i][j-1],smax[i+succ(j-1)][j-1]),
	    smin[i][j]=min(smin[i][j-1],smin[i+succ(j-1)][j-1]);

    dfs(1,n);
    return 0*printf("%lld\n",ans);
}

  

posted @ 2019-01-29 01:42  wang9897  阅读(216)  评论(0编辑  收藏  举报