exam8.3
rank25凉凉好吧。。。。。。
T1:。。。
一开始完全**
手玩给的那张图(不放图,我太饿把图吃了)
发现对于任一个节点,减去上一个比他小的斐波那契数就是父节点,
于是,欢乐敲代码(话说别人好像是二分查找,而我直接打表+lower_bound,<algorithm>大法好)
过编译,于是……
样例死了。绝望.png
一个小时后,过了。
结果MLE80好吧。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
#define cin(a) scanf("%lld",&a)
#define cout1(a) printf("%lld\n",a)
#define cout2(a) printf("%lld ",a)
int a[65]={1,1};
int f[600050][65];
int m,n;
void pre()
{
for(int q=2;q<=64;q++)
a[q]=a[q-1]+a[q-2];
}
int tot;
int work(int x,int y)
{
if(x==y)
return x;
int dx,dy;
int tx=x,ty=y;
int k1=++tot,k2=++tot;
f[k1][0]=x,f[k2][0]=y;
for(int q=1;;q++)
{
if(tx==1)
{
dx=q;
break;
}
int l=lower_bound(a+1,a+64,tx)-a;
if(tx<=a[l]) --l;
f[k1][q]=tx-a[l];
tx-=a[l];
}
for(int q=1;;q++)
{
if(ty==1)
{
dy=q;
break;
}
int l=lower_bound(a+1,a+64,ty)-a;
if(ty<=a[l]) --l;
f[k2][q]=ty-a[l];
ty-=a[l];
}
for(int q=0;;q++)
if(f[k1][dx-q]!=f[k2][dy-q])
return f[k1][dx-q+1];
}
signed main()
{
pre();
cin(m);
for(int q=1,x,y;q<=m;q++)
{
cin(x),cin(y);
cout1(work(x,y));
}
}
P.S.如果哪位知道我为什么MLE,欢迎告诉来骂我
updata:已A,可改为滚动数组
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
#define cin(a) scanf("%lld",&a)
#define cout1(a) printf("%lld\n",a)
#define cout2(a) printf("%lld ",a)
int a[100]={1,1};
int f[2][100];
int m,n;
void pre()
{
for(int q=2;q<=64;q++)
a[q]=a[q-1]+a[q-2];
}
int tot;
int work(int x,int y)
{
if(x==y)
return x;
int dx,dy;
memset(f,0,sizeof(f));
int tx=x,ty=y;
int k1=0,k2=1;
f[k1][0]=x,f[k2][0]=y;
for(int q=1;;q++)
{
if(tx==1)
{
dx=q;
break;
}
int l=lower_bound(a+1,a+64,tx)-a;
if(tx<=a[l]) --l;
f[k1][q]=tx-a[l];
tx-=a[l];
}
for(int q=1;;q++)
{
if(ty==1)
{
dy=q;
break;
}
int l=lower_bound(a+1,a+64,ty)-a;
if(ty<=a[l]) --l;
f[k2][q]=ty-a[l];
ty-=a[l];
}
for(int q=0;;q++)
if(f[k1][dx-q]!=f[k2][dy-q])
return f[k1][dx-q+1];
}
signed main()
{
pre();
cin(m);
for(int q=1,x,y;q<=m;q++)
{
cin(x),cin(y);
cout1(work(x,y));
}
}
T2:
没思路,一点也没有……
想开权值线段树,感觉MLE稳了
突然发现修改、撤销、查询全是$ \Theta(1) $的,于是高兴了
带修莫队啊
不过,怎么打来着……
没事,现场YY
成功过样例了。
结果TLE40。
块长爆了
过往的人啊,请牢记,带修莫队块长是$n^{ \frac {2} {3} }$
仍是代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define cin(a) scanf("%d",&a)
#define cout1(a) printf("%d\n",a)
#define cout2(a) printf("%d ",a)
const int maxn=3e5+5;
struct node{
int l,r,wh,tim,ans;
}a[maxn];
struct cha{
int k,tim;
}b[maxn];
int tot1,tot2;
int block[maxn];
int t[maxn];
int c[maxn];
int l,r;
int m,n;
inline bool h233(node a,node b)
{
if(block[a.l]==block[b.l])
return a.r<b.r;
return block[a.l]<block[b.l];
}
inline bool h234(cha a,cha b)
{
return a.tim<b.tim;
}
inline bool h235(node a,node b)
{
return a.tim<b.tim;
}
inline void work(const int k)
{
register int bj;
for(bj=1;;++bj)
{
register int p=b[bj].k;
if(b[bj].tim>a[k].tim||bj>tot2)
break;
if(p==r)
--t[c[p]],++t[c[p+1]];
if(p==l-1)
++t[c[p]],--t[c[p+1]];
c[p]^=c[p+1],c[p+1]^=c[p],c[p]^=c[p+1];
}
--bj;
while(l<a[k].l) --t[c[l++]];
while(l>a[k].l) ++t[c[--l]];
while(r<a[k].r) ++t[c[++r]];
while(r>a[k].r) --t[c[r--]];
a[k].ans=t[a[k].wh];
for(;bj;--bj)
{
int p=b[bj].k;
if(p==r)
--t[c[p]],++t[c[p+1]];
if(p==l-1)
++t[c[p]],--t[c[p+1]];
c[p]^=c[p+1],c[p+1]^=c[p],c[p]^=c[p+1];
}
}
signed main()
{
cin(n),cin(m);
int len=1+pow(n,0.666666);
for(register int q=1;q<=n;++q)
block[q]=(q-1)/len+1;
for(register int q=1;q<=n;++q)
cin(c[q]);
for(register int q=1,x;q<=m;++q)
{
cin(x);
if(x==1)
{
cin(a[++tot1].l),
cin(a[tot1].r),
cin(a[tot1].wh);
a[tot1].tim=q;
}
else
{
cin(b[++tot2].k);
b[tot2].tim=q;
}
}
sort(a+1,a+tot1+1,h233);
sort(b+1,b+tot2+1,h234);
l=1,r=0;
for(register int q=1;q<=tot1;++q)
work(q);
sort(a+1,a+tot1+1,h235);
for(register int q=1;q<=tot1;++q)
cout1(a[q].ans);
}
T3:
没啥想说的,真没啥想说的,暴力都不会,水8分放弃
于是,结束了。
exam8.3的更多相关文章
- exam8.29
咕了好几篇后... 我终于开始重新写了 T1: 不会,没思路,暴搜还可能会(一开始我以为暴搜时间复杂度为$\Theta (mn ^ k)$) 于是码出了暴搜... 跑一遍$(4,4,5)$,然后... ...
- Applet web端对文件的读取方式
转载:http://www.exam8.com/computer/Java/zonghe/200708/659876.html ---- 我们知道,在Java Applet中出于安全性考虑,Apple ...
- laravel7 百度智能云检测内容及图片
1:百度智能云,获取AppID,API Key,Secret Key https://console.bce.baidu.com/ai/?_=1642339692640&exraInfo=ai ...
随机推荐
- Java 8 新特性--Lambda表达式作为方法参数
Lambda表达式的使用场景: 当方法的参数是一个函数式接口时,可以使用Lambda表达式进行简化—— 首先,前提是Runnable接口是一个函数式接口,经过查看源码得知,确实如此: 将Runnabl ...
- Vue使用指南(二)
'''1.指令 ***** 文本指令 属性指令 方法(事件)指令 表单指令 条件指令 循环指令 2.组件 *** 局部组件 全局组件 父子组件间的交互''' 文件指令 <body> < ...
- [Done] Codeforces Round #562 (Div. 2) 题解
A - Circle Metro 模拟几百步就可以了. B - Pairs 爆搜一下,时间复杂度大概是 $O(4 * n)$ Code: 56306723 C - Increasing by Modu ...
- java.lang.AbstractMethodError: null
在使用springcloud的时候运行报这个错,原因是版本冲突导致的,在idea中创建springcloud项目的时候,这里默认是${spring-cloud.version},但是如果你使用的是高版 ...
- GRIT VIEW删除事件
1.点选表格后找到事件 RowCommand 2.輸入gvGroupUser_RowCommand后双击 ------注分 ...
- Python 帮你玩微信跳一跳 GitHub Python脚本
前言想自己搞游戏小程序的 在github 有人已经利用 python程序, 通过adb 获取不同型号安卓手机的系统截图,然后通过计算小人与目标位置距离之后得到准确的触摸时间,再通过 开发者模式里的 a ...
- JSONObject和URL以及HttpURLConnection的使用
1 将java对象类转成json格式 首先引入依赖jar文件 注意依赖文件的版本号,高版本可能没有对应的类 2 我的实体类中包含内部类注意内部类要public才能被序列化成json格式 import ...
- 用BIO手写实现Redis客户端的探究(拒绝Jedis)
在Redis的使用过程中,大多数人都是使用现成的客户端,如Jedis,Redisson,Lettuce.因此本文研究用BIO的方式手写Redis客户端尝试,对遇到的问题进行探究及总结. Redis通讯 ...
- SHELL字符串处理技巧(${}、##、%%)
在SHELL编程中,经常要处理一些字符串变量.比如,计算长度啊.截取子串啊.字符替换啊等等,常常要用到awk.expr.sed.tr等命令.下面给大家介绍个简单的字符串处理方法,用不着嵌套复杂的子 ...
- 关于ubuntu软件图标的问题
原因是这样的,有一次我更新我的IDEA之后,程序图标就不见了. 怎么说呢,就是以下显示的这样. 在Frequent中显示正常, 在All中却没有!!! 是的,它就是在一边有一边没有... 奇了怪了. ...