作为橙名来水了一发……

这次题目就比上次良心多了。7题有5题会做。

然而风格仍然很怪异……还是练少了?


A

水题。不过一开始没注意细节挂了几发,罚时罚的真痛……

明显是能除以 $k$ 就除以 $k$,否则就 $-1$。但注意不能直接最裸的模拟。

时间复杂度 $O(T\log n)$。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int t;
ll n,k,cnt;
int main(){
t=read();
while(t--){
n=read();k=read();
cnt=;
while(n){
if(n%k==) n/=k,cnt++;
else{
ll t=n/k*k;
cnt+=n-t;
n=t;
}
}
cout<<cnt<<endl;
}
}

B

堪比NOIP2017D1T2的模拟程序。

有很多细节,然后我的同学们就全挂了,就我一个幸存???

用 $y[i]$ 表示到第 $i$ 行时共会循环多少次,$hhh[i]$ 表示 $y[i]$ 是否溢出。

代码写着也不是很难受。时间复杂度 $O(n)$。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int l,stk[maxn],tp;
char op[maxn][];
bool hhh[maxn];
ll x,y[maxn],a[maxn];
int main(){
l=read();
FOR(i,,l){
scanf("%s",op[i]+);
if(op[i][]=='f') a[i]=read();
}
y[]=;
FOR(i,,l){
if(op[i][]=='f'){
stk[++tp]=i;
y[i]=y[i-]*a[i];
if(hhh[i-] || y[i]>=(1ll<<)) hhh[i]=true;
}
else{
if(op[i][]=='e') y[i]=y[stk[tp]-],hhh[i]=hhh[stk[tp]-],tp--;
else{
y[i]=y[i-];hhh[i]=hhh[i-];
if(hhh[i]) return puts("OVERFLOW!!!"),;
x+=y[i];
if(x>=(1ll<<)) return puts("OVERFLOW!!!"),;
}
}
}
cout<<x<<endl;
}

C

有一点点点点的难度。

发现对于一个点,与它前 $k$ 近的点是一个长度为 $k$ 的区间。

枚举这个区间,对于一个区间最优答案在中点取得。对所有中点取个最优即可。

时间复杂度 $O(\sum n)$。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int t,n,k,a[maxn],x,y;
int main(){
t=read();
while(t--){
n=read();k=read()+;
FOR(i,,n) a[i]=read();
y=1e9;
FOR(l,,n-k+){
int r=l+k-,mid=(a[l]+a[r])>>;
if(a[r]-a[l]<y) y=a[r]-a[l],x=mid;
}
printf("%d\n",x);
}
}

D

比B和C还水的水题。

我们假设分割点是 $x_1,x_2,x_3,\cdots,x_{k-1},x_k$。注意 $x_1=1$。那么题目中的式子就是 $\sum suf[x_i]$。($suf$ 是后缀和)

那么在 $suf[2],suf[3],\cdots,suf[n]$ 中取前 $k-1$ 大,再与 $suf[1]$ 相加就是答案。

时间复杂度 $O(n\log n)$。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,k,a[maxn];
ll suf[maxn],ans;
int main(){
n=read();k=read();
FOR(i,,n) a[i]=read();
ROF(i,n,) suf[i]=suf[i+]+a[i];
sort(suf+,suf+n+,greater<ll>());
ans=suf[];
FOR(i,,k) ans+=suf[i];
cout<<ans;
}

E

开始有难度了。

首先发现对于左端点相同的区间,只需要保留右端点最右的一个。

(以下设询问区间为 $[x,y]$)

然后假设 $[x,y_0]$ 已经被完全覆盖了,那么下一个要选的区间的左端点要 $\le y_0$,且右端点尽可能右。

设 $mx[l]$ 表示左端点 $\le l$ 的区间中的最右右端点。

那么问题就变成从 $x$ 开始跳,跳到 $mx[x]$,再跳到 $mx[mx[x]]$……一直跳跳到 $\ge y$ 为止,问要多少步。

那么就是显然的倍增了。

设 $to[i][j]$ 表示从 $i$ 开始跳 $2^j$ 会跳到哪。那么有 $to[i][0]=mx[i],to[i][j]=to[to[i][j-1]][j-1]$。

对于每个询问,先判无解。

否则从 $19$ 到 $0$ 枚举 $j$。如果 $to[x][j]<y$ 那么把 $x$ 跳到 $to[x][j]$。

这时当 $to[x][0]<y$ 那么无解,因为已经跳了 $2^20$ 步了,如果还没跳到那么说明没法再跳到了(只能在原地跳环)。否则因为有解,所以枚举完后再跳一步一定能 $\ge y$。

时间复杂度 $O(n+(q+A)\log A)$。($A$ 为端点坐标最大值)

代码细节,为了不让 $to[i][j]<i$,一开始把 $mx[i]$ 设成 $i$ 就行了,不影响答案。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,m,k=,mx[maxn],to[maxn][];
int main(){
n=read();m=read();
FOR(i,,k) mx[i]=i;
FOR(i,,n){
int l=read(),r=read();
mx[l]=max(mx[l],r);
}
FOR(i,,k) mx[i]=max(mx[i-],mx[i]);
FOR(i,,k) to[i][]=mx[i];
FOR(j,,) FOR(i,,k) to[i][j]=to[to[i][j-]][j-];
while(m--){
int x=read(),y=read(),cnt=;
ROF(i,,) if(to[x][i]<y) cnt+=<<i,x=to[x][i];
if(to[x][]<y) puts("-1");
else printf("%d\n",cnt+);
}
}

F,G

还不会,以后再来搞。

Educational Round 66 题解的更多相关文章

  1. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  2. Codeforces Educational Round 33 题解

    题目链接   Codeforces Educational Round 33 Problem A 按照题目模拟,中间发现不对就直接输出NO. #include <bits/stdc++.h> ...

  3. Educational Round 64 题解

    前言: 这场太难了……我一个紫名只打出两题……(虽说感觉的确发挥不够好) 一群蓝绿名的dalao好像只打了两题都能升分的样子…… 庆幸的是最后A出锅然后unr了>///< 写一波题解纪念这 ...

  4. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  5. Educational Codeforces Round 66 差G

    Educational Codeforces Round 66 F 题意:长度为 n 的序列,求有多少个区间 \([l,r]\) ,使得其构成了一个 1~r-l+1 的排列. \(n \le 3*10 ...

  6. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  7. [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]

    这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...

  8. [CodeForces]Educational Round 52

    幸好我没有打这场,我VP的时候在C题就卡死了,我果然还是太菜了. A Vasya and Chocolate 题意:一个巧克力\(c\)元,买\(a\)赠\(b\),一共有\(n\)元,问能买几个巧克 ...

  9. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

随机推荐

  1. Field redisTemplate in xxxxxx required a bean of type 'org.springframework.data.redis.core.RedisTemplate' that could not be found.

    *************************** APPLICATION FAILED TO START *************************** Description: Fie ...

  2. 分布式文件系统fastdfs搭建

    https://blog.csdn.net/qq_33009107/article/details/90641940 #Tracker 端口号 22122 启动tracker /etc/init.d/ ...

  3. MobaXterm的安装和使用

    MobaXterm的安装和使用 安装 1 下载网址:https://mobaxterm.mobatek.net/,选择“Download”,选择免费版的下载. 2 解压压缩包,双击exe文件安装软件, ...

  4. Mysql中的变量

    Mysql中的变量众多(即运行的配置),如:事务相关的.连接相关的.查询优化类的等等. 变量的作用域: 1.临时作用域 session级别:即打开一个与mysql server会话的基础上的作用域,变 ...

  5. 【spring boot】【redis】spring boot 集成redis的发布订阅机制

    一.简单介绍 1.redis的发布订阅功能,很简单. 消息发布者和消息订阅者互相不认得,也不关心对方有谁. 消息发布者,将消息发送给频道(channel). 然后是由 频道(channel)将消息发送 ...

  6. 单片机成长之路(stm8基础篇)- 025 stm8 时钟切换

    stm8 时钟切换; /************************************ 时钟设置 ************************************/ // 时钟 0: ...

  7. 安卓访问https错误,访问http可以,可能是nginx ssl证书配置有问题

    开发中遇到react-native生成的android访问UAT和开发环境的http api都可以,但是访问生产环境的https就报错,还有就是第三方webhook调用你https网站的api也可能会 ...

  8. 优化、分析Mysql表读写、索引等操作的sql语句效率优化问题

    为什么要优化: 随着实际项目的启动,数据库经过一段时间的运行,最初的数据库设置,会与实际数据库运行性能会有一些差异,这时我们 就需要做一个优化调整. 数据库优化这个课题较大,可分为四大类: >主 ...

  9. 消息队列mq总结

    一.消息队列概述消息队列中间件是分布式系统中重要的组件,主要解决应用解耦,异步消息,流量削锋等问题,实现高性能,高可用,可伸缩和最终一致性架构.目前使用较多的消息队列有ActiveMQ,RabbitM ...

  10. Scanner 中next()和nexline()方法的区别

      在java实现字符窗口的输入时,很多人更喜欢选择使用扫描器scanner,它操作起来比较简单.在编程的过程中,我发现用scanner实现字符串的输入有两种方法,一种是next(),另一种是next ...