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. 使用Hugo框架搭建博客的过程 - 主题配置

    前言 博客部署完成后,恭喜你可以发表第一篇:Hello world!但是LoveIt这么好用的主题,不配置一番可惜了. 基本功能配置 主题配置最好参考已有的配置,比如LoveIt作者写的介绍,还有主题 ...

  2. JMeter之BeanShell常用内置对象

    一.什么是Bean Shell BeanShell是一种完全符合Java语法规范的脚本语言,并且又拥有自己的一些语法和方法; BeanShell是一种松散类型的脚本语言(这点和JS类似); BeanS ...

  3. celery task异步任务

    业务端后台:通过python manage运行 运行用例时,用python manage运行时会卡,影响效率 celery task 本身自己也是个服务,异步处理case 异步:小明去给我买个东西,我 ...

  4. 手把手0基础Centos下安装与部署paddleOcr 教程

    !!!以下内容为作者原创,首发于个人博客园&掘金平台.未经原作者同意与许可,任何人.任何组织不得以任何形式转载.原创不易,如果对您的问题提供了些许帮助,希望得到您的点赞支持. 0.paddle ...

  5. 12. Mysql基础入门

    课程大纲 • 数据库概述 • MySQL基本操作 • MySQL索引基础 • MySQL高级特性

  6. [刘阳Java]_MyBatis_实体关系映射_第8讲

    MyBatis既然是一个ORM框架,则它也有像Hibernate那样的一对多,多对多,多对一的实体关系映射功能.下面我们就来介绍一下如何使用MyBatis的实体关系映射 1.MyBatis实体关系映射 ...

  7. 【LeetCode】137. 只出现一次的数字 II(剑指offer 56-II)

    137. 只出现一次的数字 II(剑指offer 56-II) 知识点:哈希表:位运算 题目描述 给你一个整数数组 nums ,除某个元素仅出现 一次 外,其余每个元素都恰出现 三次 .请你找出并返回 ...

  8. 编写mysql多实例启动脚本

    脚本原理: 启动MySQL动作: mysqld_safe来执行启动 停止MySQL动作: 使用mysqladmin来执行停止动作 重启的MySQL动作:    原理就是先停止,然后再启动 但是要注意: ...

  9. form 表单提交的另一种方式 js

    <html> <head> <script type="text/javascript"> function formSubmit() { fm ...

  10. frame window 和open 的关系

    建立一个如下的关系框架 windowA.html <!DOCTYPE html> <html lang="en"> <head> <met ...