Codeforces Round #426 (Div. 1) (ABCDE)

Posted uid001

tags:

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

1. 833A The Meaningless Game

大意: 初始分数为$1$, 每轮选一个$k$, 赢的人乘$k^2$, 输的人乘$k$, 给定最终分数, 求判断是否成立.

判断一下$acdot b$是否是立方数, 以及能否被那个立方的因子整除即可. cbrt竟然有误差, 特判了一下, 好坑 

技术图片
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl ‘
‘
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<‘,‘;hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<0||p>9)p=getchar();while(p>=0&&p<=9)x=x*10+p-0,p=getchar();return x;}
//head


int main() {
    int n;
    scanf("%d", &n);
    while (n--) {
        int a, b;
        scanf("%d%d", &a, &b);
        ll x = (ll)a*b, t = cbrt(x);
        while (t*t*t>x) --t;
        while (t*t*t<x) ++t;
        puts(t*t*t==x&&a%t==0&&b%t==0?"Yes":"No");
    }
}
View Code

 

 

2. 833B The Bakery

大意: 给定$n$元素序列, 求划分为最多$x$段, 每段的贡献为不同元素数, 求最大贡献.

设$dp_{i,j}$为前$i$个数分成$j$段的最大值, 开$k$棵线段树, 位置$x$维护dp[x-1][j]+[x...i]的贡献即可

技术图片
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl ‘
‘
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<‘,‘;hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<0||p>9)p=getchar();while(p>=0&&p<=9)x=x*10+p-0,p=getchar();return x;}
//head



const int N = 35100;
int n,k,a[N],pre[N],vis[N];
int dp[N][50];
//dp[i][j] = 前i个数,分成j段的最大值
//要支持区间加, 查询区间最值
struct {
    int ma[N<<2],tag[N<<2];
    void pd(int o) {
        if (tag[o]) {
            ma[lc]+=tag[o],tag[lc]+=tag[o];
            ma[rc]+=tag[o],tag[rc]+=tag[o];
            tag[o]=0;
        }
    }
    void add(int o, int l, int r, int ql, int qr, int v) {
        if (ql<=l&&r<=qr) return ma[o]+=v,tag[o]+=v,void();
        pd(o);
        if (mid>=ql) add(ls,ql,qr,v);
        if (mid<qr) add(rs,ql,qr,v);
        ma[o]=max(ma[lc],ma[rc]);
    }
} tr[55];

int main() {
    scanf("%d%d", &n, &k);
    REP(i,1,n) { 
        scanf("%d",a+i);
        pre[i] = vis[a[i]];
        vis[a[i]] = i;
    }
    REP(i,1,n) {
        REP(j,0,k-1) tr[j].add(1,1,n,pre[i]+1,i,1);
        REP(j,1,k) dp[i][j] = tr[j-1].ma[1];
        if (i==n) break;
        REP(j,1,k-1) tr[j].add(1,1,n,i+1,i+1,dp[i][j]);
    }
    printf("%d
", dp[n][k]);
}
View Code

 

 

3. 833C Ever-Hungry Krakozyabra

大意: 给定$L,R$, 将区间$[L,R]$的每个数去除数位$0$后对数位进行排序, 求一共能得到多少种数.

先特判掉1e18, 所有可能得到的数最多为$inom{18+9}{9}=1562275$, 可以直接暴力枚举每个数$x$, 判断$x$是否能在区间$[L,R]$得到即可. 判断合法性本来写的$O(18^2)$的暴力贪心, 结果TLE on test 70. 按照官方题解改成复杂度$O(10*18)$的$dfs$就过了...... 看评论区说似乎有不用暴力枚举的做法, 没太懂 

技术图片
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl ‘
‘
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<‘,‘;hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<0||p>9)p=getchar();while(p>=0&&p<=9)x=x*10+p-0,p=getchar();return x;}
//head
 
 
 
int ans,len,flag,cnt,a[20],x[20],y[20];
ll L, R, fac[20];


int solve(int d, int l1, int l2) {
    if (!l1&&!l2||d<0) return 1;
    int U=l1?x[d]:0,D=l2?y[d]:9;
    REP(i,U,D) if (a[i]) {
        --a[i];
        if (solve(d-1,l1&&x[d]==i,l2&&y[d]==i)) return ++a[i],1;
        ++a[i];
    }
    return 0;
}

int chk() {
    return solve(len-1,1,1);
}
 
//生成所有合法的数
void dfs(int d, int pre) {
    if (d>len) return;
    REP(i,pre,9) { 
        ++a[i],++cnt;
        a[0] = len-cnt;
        ans += chk();
        dfs(d+1,i);
        --a[i],--cnt;
    }
}
 
int main() {
    fac[0] = 1;
    REP(i,1,18) fac[i] = fac[i-1]*10;
    scanf("%lld%lld",&L,&R);
    if (R==fac[18]) --R, flag = 1;
    if (L==fac[18]) --L;
    ll t = L;
    while (t) x[len++]=t%10,t/=10;
    t = R, len = 0;
    while (t) y[len++]=t%10,t/=10;
    dfs(1,1);
    printf("%d
",ans);
}
View Code

 

 

4. 

 

5. 833E Caramel Clouds

大意: 给定$n$朵云, 第$i$朵出现时间范围$[l_i,r_i]$, 删除需要花费$c_i$, 初始时刻为$0$, 预算为$C$. 给定$m$个询问$k_i$, 求一棵需要照$k_i$时间阳光的花最快什么时间长成, 最多删除两朵云, 询问独立.

参考的这个https://www.cnblogs.com/ECJTUACM-873284962/p/7265224.html

主要思路就是依次处理每个时间段, 预处理每个时刻的最大光照时间.

技术图片
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl ‘
‘
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<‘,‘;hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<0||p>9)p=getchar();while(p>=0&&p<=9)x=x*10+p-0,p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


int n, C, cost[N], tag[N], b[N];
pii tr1[N],tr2[N];

//树状数组维护区间最大次大
void add(int id, int x, int v) {
    x = lower_bound(b+1,b+1+*b,x)-b;
    for (; x<=*b; x+=x&-x) { 
        if (tr1[x].y==id) tr1[x].x = max(tr1[x].x,v);
        else if (tr2[x].x<v) tr2[x] = pii(v,id);
        if (tr1[x]<tr2[x]) swap(tr1[x],tr2[x]);
    }
}
int qry(int id, int x) {
    x = upper_bound(b+1,b+1+*b,x)-b-1;
    int ret = 0;
    for (; x; x^=x&-x) {
        if (id==tr1[x].y) ret=max(ret,tr2[x].x);
        else ret=max(ret,tr1[x].x);
    }
    return ret;
}

int main() {
    scanf("%d%d", &n, &C);
    vector<pii> events;
    REP(i,1,n) {
        int l,r;
        scanf("%d%d%d",&l,&r,cost+i);
        events.pb(pii(l,i));
        events.pb(pii(r,i));
        b[i] = cost[i];
    }
    events.pb(pii(0,0));
    events.pb(pii(2e9,0));
    sort(events.begin(),events.end());
    sort(b+1,b+1+n),*b=unique(b+1,b+1+n)-b-1;
    REP(i,0,*b+5) tr1[i].y=tr2[i].y=-1;
    vector<pii> ans;
    map<pii,int> len;
    set<int> s;
    int mx = 0;
    if (events[0].y) s.insert(events[0].y);
    for (int i=1; i<events.size(); ++i) { 
        int d = events[i].x-events[i-1].x;
        if (d>0&&s.size()<=2) {
            int p = 0, q = 0;
            if (s.size()) p = *s.begin();
            if (s.size()==2) q = *s.rbegin();
            int start = -1;
            if (!p) { 
                start = mx;
                len[{0,0}] += d;
            }
            else if (!q) {
                if (cost[p]<=C) {
                    start = len[{p,0}]+len[{0,0}];
                    //找一个q, 使得len[{p,q}]+len[{q,0}]的最大
                    int ma = tag[p]; //相交的情况
                    //不相交的情况
                    ma = max(ma, qry(p,C-cost[p]));
                    start += ma;
                    len[{p,0}] += d;
                    add(p,cost[p],len[{p,0}]);
                }
            }
            else if (cost[p]+cost[q]<=C) {
                start = len[{p,q}]+len[{p,0}]+len[{q,0}]+len[{0,0}];    
                len[{p,q}] += d;
                tag[p] = max(tag[p], len[{p,q}]+len[{q,0}]);
                tag[q] = max(tag[q], len[{p,q}]+len[{p,0}]);
            }
            if (~start&&start+d>mx) {
                mx = start+d;
                ans.pb(pii(mx, events[i].x));
            }
        }
        int id = events[i].y;
        if (!id) continue;
        if (s.count(id)) s.erase(id);
        else s.insert(id);
    }
    int m;
    scanf("%d", &m);
    while (m--) {
        int k;
        scanf("%d", &k);
        auto p = lower_bound(ans.begin(),ans.end(),pii(k,0));
        printf("%d
", p->y-(p->x-k));
    }
}
View Code

 

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

codeforces round #426 div 2

Codeforces Round #426 A

Codeforces Round #426 (Div. 1) (ABCDE)

Codeforces Round #426 (Div. 2)A. The Useless Toy

Codeforces Round #426 (Div. 2) C. The Meaningless Game (二分 or pow函数)

Codeforces Round #426 (Div. 2)B. The Festive Evening