T1

本次考试最水的一道题,然而我sb,前一个小时,找了一大堆跟题目无关的性质,干脆打了个20pts的表,然后就走了,最后几分钟才看出来,匆匆码出来,结果段错误,然后考试就结束了。

好吧,段错误是UB,返回值的原因,%%%TLEer,加个return就好了。

就是找规律,\(fa_{now}=now-f_{i}\) ,其中 \(f_{i} < now\le f_{i+1}\) 即第一个比 \(now\) 小的斐波那契数,然后就没啥了,记得开long long。

Code
#include<cstdio>
#include<algorithm>
#define re register
#define int long long
namespace OMA
{
int m;
int f[65]={0,1,1};
inline int read()
{
int s=0,w=1; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*w;
}
int LCA(int a,int b)
{
if(a==1||b==1)
{ return 1; }
if(a==b)
{ return a; }
int temp1 = std::lower_bound(f+1,f+61,a)-f-1;
int temp2 = std::lower_bound(f+1,f+61,b)-f-1;
while(a-f[temp1]>=b)
{ a -= f[temp1],temp1 = std::lower_bound(f+1,f+temp1,a)-f-1; }
while(b-f[temp2]>=a)
{ b -= f[temp2],temp2 = std::lower_bound(f+1,f+temp2,b)-f-1; }
if(a==1||b==1)
{ return 1; }
if(a==b)
{ return a; }
return LCA(a-f[temp1],b-f[temp2]);
}
signed main()
{
f[0]=0;
m = read();
for(re int i=3; i<=60; i++)
{ f[i] = f[i-1]+f[i-2]; }
for(re int i=1; i<=m; i++)
{ int a=read(),b = read(); printf("%lld\n",LCA(a,b)); }
return 0;
}
}
signed main()
{ return OMA::main(); }

T2

暴力拿了30pts,后来时限开大,拿了60pts。

正解很多,这里是二分。

首先按照颜色和位置排序,然后考虑题目中的两个操作。

第一个询问操作,只需要对排序后的数组二分查找,下标差即是答案。

第二个修改操作,因为修改并不会改变同种颜色的相对顺序,所以只需要找到位置并进行修改就好了。

其实也是挺水的

线段树做法

Code
#include<cstdio>
#include<algorithm>
#define MAX 300001
#define re register
namespace OMA
{
int n,m;
int a[MAX];
struct node
{
int c;
int pos;
friend bool operator <(const node &x,const node &y)
{ return (x.c!=y.c)?x.c<y.c:x.pos<y.pos; }
}col[MAX];
inline int read()
{
int s=0,w=1; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*w;
}
inline void swap(int &a,int &b)
{ int t=a; a=b; b=t; }
signed main()
{
n = read(),m = read();
for(re int i=1; i<=n; i++)
{ a[i] = col[col[i].pos = i].c = read(); }
std::sort(col+1,col+1+n);
for(re int i=1; i<=m; i++)
{
int opt = read();
if(opt==1)
{
int l = read(),r = read(),c = read();
int L = std::lower_bound(col+1,col+1+n,node{c,l})-col;
int R = std::upper_bound(col+1,col+1+n,node{c,r})-col-1;
printf("%d\n",R-L+1);
}
if(opt==2)
{
int x = read();
if(a[x]==a[x+1])
{ continue; }
col[std::lower_bound(col+1,col+1+n,node{a[x],x})-col].pos = x+1;
col[std::lower_bound(col+1,col+1+n,node{a[x+1],x+1})-col].pos = x;
swap(a[x],a[x+1]);
}
}
return 0;
}
}
signed main()
{ return OMA::main(); }

upd on 2021-08-22

模拟题里有道回滚莫队,然而我分块都不太会,所以学了学,发现这道题可以拿分块硬草过去。

如果直接按 \(\sqrt{n}\) 来分,会 \(MLE\) ,然后,我选的是200MIB来卡,经过一波计算,发现块长应为1740左右,大概是 \(n^{\frac{19}{32}}\),这样就分出了大概170个块,不会MLE,内存200MIB左右,最劣复杂度 \(O(m(\frac{n}{T}+T))\),其中 \(T\) 为块的大小 \(n^{\frac{19}{32}}\),luogu跑了5.1s,最慢的点855ms。还是慎用吧

bb那么多,其实直接用个short就行,made

然而oj慢的很,95pts卡不过去,卡不动了。虽然有人过了

Code
#include<cmath>
#include<cstdio>
#define MAX 300010
#define re register
const int LEN = 220;
namespace some
{
struct stream
{
template<typename type>inline stream &operator >>(type &s)
{
int w=1; s=0; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*=w,*this;
}
}cin;
inline void write(int x)
{
int sta[35],top = 0;
do
{
sta[++top] = x-(x/10)*10;
x /= 10;
}while(x);
while(top)
{ putchar(sta[top--]+'0'); }
putchar('\n');
}
}using namespace some;
namespace OMA
{
int n,m,len;
int col[MAX];
short id[MAX],sum[LEN][MAX];
struct BLOCK
{
/*inline void update(int p1,int p2)
{
sum[id[p1]][col[p1]]--;
sum[id[p1]][col[p2]]++;
sum[id[p2]][col[p1]]++;
sum[id[p2]][col[p2]]--;
int t = col[p1];
col[p1] = col[p2]; col[p2] = t;
}*/
inline int query(int l,int r,int c)
{
int res = 0;
int p1 = id[l],p2 = id[r];
if(p1==p2)
{
for(re int i=l; i<=r; i++)
{
if(col[i]==c)
{ res++; }
}
return res;
}
for(re int i=l; id[i]==p1; i++)
{
if(col[i]==c)
{ res++; }
}
for(re int i=p1+1; i<=p2-1; i++)
{ res += sum[i][c]; }
for(re int i=r; id[i]==p2; i--)
{
if(col[i]==c)
{ res++; }
}
return res;
}
}block;
signed main()
{
cin >> n >> m; len = pow(n,5.0/8.0);
for(re int i=1; i<=n; i++)
{
cin >> col[i];
id[i] = (i-1)/len+1;
sum[id[i]][col[i]]++;
}
for(re int i=1,opt,l,r,c,x; i<=m; i++)
{
cin >> opt;
if(opt==1)
{
//int l,r,c;
cin >> l >> r >> c;
//printf("%d\n",block.query(l,r,c));
write(block.query(l,r,c));
}
if(opt==2)
{
//int x;
cin >> x;
if(x==n)
{ continue ; }
//block.update(x,x+1);
int p1 = x,p2 = x+1;
sum[id[p1]][col[p1]]--;
sum[id[p1]][col[p2]]++;
sum[id[p2]][col[p1]]++;
sum[id[p2]][col[p2]]--;
int t = col[p1];
col[p1] = col[p2]; col[p2] = t;
}
}
return 0;
}
}
signed main()
{ return OMA::main(); }

T3

没改出来

noip9的更多相关文章

随机推荐

  1. 第二届 BJD wp(reverse和crypto)

    re 1.第一题拖入ida,flag就是直接明文摆着 2.第二题是8086的程序,拖入ida,发现有个jmp无限跳转,可能是段寄存器被修改了,ida无法将后面的汇编识别出来,所以后面才有很多无效数据, ...

  2. java基础---设计模式(2)

    结构型模式 出处:https://blog.csdn.net/zhangerqing/article/details/8239539 一.适配器模式 适配器模式将某个类的接口转换成客户端期望的另一个接 ...

  3. ES6新增语法(二)——函数和参数

    箭头函数 箭头函数:将原来函数的function关键字和函数名都删掉,并使用"=>"连接参数列表和函数体. 箭头函数语法: (参数1,参数2)=>{ 函数体 } 注意点 ...

  4. java课堂动手动脑及课后实验总结

      动手动脑一:枚举   输出结果: false false true SMALL MEDIUM LARGE 分析和总结用法 枚举类型的使用是借助ENUM这样一个类,这个类是JAVA枚举类型的公共基本 ...

  5. 计算机毕业设计选题大合集,含ssm,springboot,小程序,php,python

    1基于springboot医院急诊系统 2基于springboot校园闲置物品租售系统 3基于springboot校园闲置物品交易网站 4基于springboot图书网站 5基于springboot外 ...

  6. 在Java中,负数的绝对值竟然不一定是正数!!!

    绝对值是指一个数在数轴上所对应点到原点的距离,所以,在数学领域,正数的绝对值是这个数本身,负数的绝对值应该是他的相反数. 这几乎是每个人都知道的. 在Java中,想要获得有个数字的绝对值,可以使用ja ...

  7. CSAPP:bomblab

    BOMBLAB实验总结 CSAPP实验BOMB,很头疼,看不懂,勉强做完了. 答案是这样的: Border relations with Canada have never been better. ...

  8. js里的发布订阅模式及vue里的事件订阅实现

    发布订阅模式(观察者模式) 发布订阅模式的定义:它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知. 发布订阅模式在JS中最常见的就是DOM的事件绑定与触发 ...

  9. WEB安全新玩法 [8] 阻止订单重复提交

    交易订单的重复提交虽然通常不会直接影响现金流和商品流,但依然会给网站运营方带来损害,如消耗系统资源.影响正常用户订单生成.制造恶意用户发起纠纷的机会等.倘若订单对象是虚拟商品,也有可能造成实际损失.订 ...

  10. js中的 true 与 false

    可判断为 false 的情况: 0,-0,NaN,undedined,"",false,null,缺省的值 可判断为 true 的情况: 除false的其他情况均可,包括负数.&q ...