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

1. 833A The Meaningless Game

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

判断一下$a\cdot 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 ‘\n‘
#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");
    }
}

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 ‘\n‘
#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\n", dp[n][k]);
}

3. 833C Ever-Hungry Krakozyabra

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

先特判掉1e18, 所有可能得到的数最多为$\binom{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 ‘\n‘
#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\n",ans);
}

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 ‘\n‘
#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\n", p->y-(p->x-k));
    }
}

原文地址:https://www.cnblogs.com/uid001/p/11621160.html

时间: 2024-11-09 02:04:40

Codeforces Round #426 (Div. 1) (ABCDE)的相关文章

Codeforces Round #261 (Div. 2)[ABCDE]

Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden 题意: 一个正方形,它的边平行于坐标轴,给出这个正方形的两个点,求出另外两个点. 分析: 推断下是否平行X轴或平行Y轴,各种if. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: A.cpp * Create Date: 2014-0

Codeforces Round #264 (Div. 2)[ABCDE]

Codeforces Round #264 (Div. 2)[ABCDE] ACM 题目地址: Codeforces Round #264 (Div. 2) 这场只出了两题TAT,C由于cin给fst了,D想到正解快敲完了却game over了... 掉rating掉的厉害QvQ... A - Caisa and Sugar[模拟] 题意: Caisa拿s美元去超市买sugar,有n种sugar,每种为xi美元yi美分,超市找钱时不会找美分,而是用sweet代替,当然能用美元找就尽量用美元找.他

Codeforces Round #426 (Div. 2) D. The Bakery(线段树维护dp)

题目链接: Codeforces Round #426 (Div. 2) D. The Bakery 题意: 给你n个数,划分为k段,每段的价值为这一段不同的数的个数,问如何划分,使得价值最大. 题解: 考虑dp[i][j]表示划分为前j个数划分为i段的最大价值,那么这就是一个n*n*k的dp, 考虑转移方程dp[i][j]=max{dp[i][k]+val[k+1][j]},我们用线段树去维护这个max,线段树上每个节点维护的值是dp[i][k]+val[k+1][j],对于每加进来的一个数a

Codeforces Round #260 (Div. 2) ABCDE

A题逗比了,没有看到All ai are distinct. All bi are distinct. 其实很水的.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 #define mnx 100002 8 9 10 struct latop{ 11 int p, q; 12 bo

Codeforces Round #531 (Div. 3) ABCDE题解

Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividing 题意: 给一个数n,然后要求你把1,2.....n分为两个集合,使得两个集合里面元素的和的差的绝对值最小. 题解: 分析可以发现,当n%4==0 或者 n%3==0,答案为0:其余答案为1.之后输出一下就好了. 代码如下: #include <bits/stdc++.h> using name

Codeforces Round #426 (Div. 2)A B C题+赛后小结

最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络赛,我似乎都没用上新学的东西,能用上新学东西的题我A不了...5555555555555555 这场CF,讲真,打的心态爆炸,首先A题无限WA,赛后看下WA的那组数据是输入有一个999999999的样例,死骗子,说好的数据是1e9呢,哪能有数据是1e10-1,于是用long long,一下子Accept接收不

Codeforces Round #200 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/344 A. Magnets time limit per test:1 second memory limit per test:256 megabytes Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets inst

Codeforces Round #105 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/148 比较简单的一场,最长的一题也才写了30行多一点 A. Insomnia cure time limit per test:2 seconds memory limit per test:256 megabytes ?One dragon. Two dragon. Three dragon?, - the princess was counting. She had trouble falling asleep, and

Codeforces Round #186 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/313 A. Ilya and Bank Account time limit per test:2 seconds memory limit per test:256 megabytes Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obl