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+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',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==&&b%t==?"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+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head const int N = ;
int n,k,a[N],pre[N],vis[N];
int dp[N][];
//dp[i][j] = 前i个数,分成j段的最大值
//要支持区间加, 查询区间最值
struct {
int ma[N<<],tag[N<<];
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]=;
}
}
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[]; int main() {
scanf("%d%d", &n, &k);
REP(i,,n) {
scanf("%d",a+i);
pre[i] = vis[a[i]];
vis[a[i]] = i;
}
REP(i,,n) {
REP(j,,k-) tr[j].add(,,n,pre[i]+,i,);
REP(j,,k) dp[i][j] = tr[j-].ma[];
if (i==n) break;
REP(j,,k-) tr[j].add(,,n,i+,i+,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+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head int ans,len,flag,cnt,a[],x[],y[];
ll L, R, fac[]; int solve(int d, int l1, int l2) {
if (!l1&&!l2||d<) return ;
int U=l1?x[d]:,D=l2?y[d]:;
REP(i,U,D) if (a[i]) {
--a[i];
if (solve(d-,l1&&x[d]==i,l2&&y[d]==i)) return ++a[i],;
++a[i];
}
return ;
} int chk() {
return solve(len-,,);
} //生成所有合法的数
void dfs(int d, int pre) {
if (d>len) return;
REP(i,pre,) {
++a[i],++cnt;
a[] = len-cnt;
ans += chk();
dfs(d+,i);
--a[i],--cnt;
}
} int main() {
fac[] = ;
REP(i,,) fac[i] = fac[i-]*;
scanf("%lld%lld",&L,&R);
if (R==fac[]) --R, flag = ;
if (L==fac[]) --L;
ll t = L;
while (t) x[len++]=t%,t/=;
t = R, len = ;
while (t) y[len++]=t%,t/=;
dfs(,);
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+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+;
#else
const int N = 1e2+;
#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+,b++*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+,b++*b,x)-b-;
int ret = ;
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,,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(,));
events.pb(pii(2e9,));
sort(events.begin(),events.end());
sort(b+,b++n),*b=unique(b+,b++n)-b-;
REP(i,,*b+) tr1[i].y=tr2[i].y=-;
vector<pii> ans;
map<pii,int> len;
set<int> s;
int mx = ;
if (events[].y) s.insert(events[].y);
for (int i=; i<events.size(); ++i) {
int d = events[i].x-events[i-].x;
if (d>&&s.size()<=) {
int p = , q = ;
if (s.size()) p = *s.begin();
if (s.size()==) q = *s.rbegin();
int start = -;
if (!p) {
start = mx;
len[{,}] += d;
}
else if (!q) {
if (cost[p]<=C) {
start = len[{p,}]+len[{,}];
//找一个q, 使得len[{p,q}]+len[{q,0}]的最大
int ma = tag[p]; //相交的情况
//不相交的情况
ma = max(ma, qry(p,C-cost[p]));
start += ma;
len[{p,}] += d;
add(p,cost[p],len[{p,}]);
}
}
else if (cost[p]+cost[q]<=C) {
start = len[{p,q}]+len[{p,}]+len[{q,}]+len[{,}];
len[{p,q}] += d;
tag[p] = max(tag[p], len[{p,q}]+len[{q,}]);
tag[q] = max(tag[q], len[{p,q}]+len[{p,}]);
}
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,));
printf("%d\n", p->y-(p->x-k));
}
}

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

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

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  2. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  3. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  4. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  5. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

  6. Codeforces Round #426 (Div. 2) C. The Meaningless Game

    C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...

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

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  8. Codeforces Round #460 (Div. 2) ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  9. Codeforces Round #426 (Div. 2) A,B,C

    A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...

随机推荐

  1. Math小记

    20161231 黄金分割比:短/长=长/(短+长)=((根号5)-1)/2 ≍ 0.618 斐波那契数列前后两项的比值存在极限.设其中三个数为a.b.(a+b),则当项数趋于无穷时有a/b=b/(a ...

  2. ModuleNotFoundError: No module named 'suit'

    ModuleNotFoundError: No module named 'suit' pip3. install suit

  3. JS简单获取当前日期时间的方法(yyyy-MM-dd hh:mm:ss)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  4. Asynchronous method in while loop 构造异步调用链

    Asynchronous method in while loop https://stackoverflow.com/questions/43064719/javascript-asynchrono ...

  5. 往hbase插入数据,你会选择哪种?

    好久,好久没有写个博客了,自从上次封闭开始,到“自闭”,有了一段时间了,哈哈^_^ . 多亏了云桌面的歇菜, 一下午啥都干不了, 突然想到,好久没有写点啥了,就写的,让时间流走有点痕迹吧 _(:з」∠ ...

  6. 荔枝派nano例子

    买回来,先短接flash芯片的14脚,然后上电,再断开14脚,开始怎么折腾都不行,最后发现是android线的问题,换成jlink ob送的android线就能找到设备了,真崩溃 lsusb,应该能看 ...

  7. 国内pip源及pip命令

    更换PIP源 PIP源在国外,速度慢,可以更换为国内源,以下是国内一些常用的PIP源. 豆瓣(douban) http://pypi.douban.com/simple/ (推荐) 清华大学 http ...

  8. 使用java计算数组方差和标准差

    使用java计算数组方差和标准差 觉得有用的话,欢迎一起讨论相互学习~Follow Me 首先给出方差和标准差的计算公式 代码 public class Cal_sta { double Sum(do ...

  9. Python模块学习filecmp文件比较

    Python模块学习filecmp文件比较 filecmp模块用于比较文件及文件夹的内容,它是一个轻量级的工具,使用非常简单.python标准库还提供了difflib模块用于比较文件的内容.关于dif ...

  10. makefile那些事儿

    一.好处 自动化编译,一条make命令,整个工程可以完全自动编译,make命令是构建大型项目的首选方案. makefile就像一个shell脚本一样,用来定义规则,一个名称包含一条或多条命令,在终端m ...