今天总体来说 菜爆了,打了 \(3\) 个暴力,没有一个是正解,并且每一个分数都低得要命。。。

主要还是太菜了。。。

第一题开题发现和昨天 \(T3\) 一样,然而因为还没学可持久化数据结构就咕掉了。。。

昨天要是学一学就好了。

然而彭师傅还想出了 \(STL\) 大法。

非常好用。

但是好多人用的还是主席树来维护。

似乎码量也不长。。。

但是我只能弱弱地说一声不会。。。。

菜就是了。。。

所以我今天要去学一学这玩意,以防明天再考。

T1:

\(T1\) 又是一个一眼只能 \(\mathcal O(n^3)\) 暴力的玩意。。。

\(\color{red} {\huge{\text{非常不友好}}}\)

但是明显地可以用 单调栈 将其优化为 \(\mathcal O(n^2)\) 的。。。。。。。。。

然而。。。。。。

这个只是最最低分的暴力。。。。

垃圾爆了。。。。

并且出题人很友好毒瘤。

暴力给了 \(30\%\) 的 \(\color{red}{\huge{\text{高}}}\) 分。

\(\color{red} {\huge{\text{非常不友好}}}\)

对于 \(Ans\) 我们要求的就是:

\[he_j-he_{j-1}-a_x =0
\]

满足这个式子的 \(i,j\) 位置。

(其中省略了取模)

所以我们只有 \(1e6\) 个取值。

然后在处理前缀和的时候开 \(1e6\) 个 \(vector\) 动态数组。

然后第一个下标是余数,然后第二个动态的是余数为第一个下标的位置

就是:

for(register int i=1;i<=n;++i)
vec[he[i] % k].push_back(i);

就是这样。

因为我们是按照顺序进行插入下标的,所以我们可以使用 \(lower_bound\) 和 $upper_bound¥ 函数进行二分查找

这就是 \(\mathcal O(log_2^n)\) 的复杂度。

因为我们要先枚举左边或者是右边的区间。

每次选择较小的那个,这样综合起来就是 \(\mathcal O(nlog_2^n)\) 的复杂度。

然后加上二分查找就是 \(O((log_2^n )^2)\)。

显然可以过。。。

#include<bits/stdc++.h>
using std::cout; using std::endl;
#define debug cout<<"debug"<<endl;
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
int eat1; FILE *eat2; char buf[1<<20],*p1 = buf,*p2 = buf;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
template<class type>inline type get()
{
type s = 0,f = 1; register char ch = gc();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io; static const int maxn = 1e6+10,maxb = 110,inf = 0x7f7f7f7f;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
typedef long long ll;
namespace xin
{
int st[maxn],tot = 0,n,k,a[maxn];
ll ans = 0;
ll he[maxn];
std::vector<int>vec[maxn];
inline void gan(int x,int l,int r)
{
if(r - x > x - l)
{
try(i,l,x)
{
register int j = (a[x] + he[i-1]) % k;
int left = std::lower_bound(vec[j].begin(),vec[j].end(),x) - vec[j].begin();
int right= std::upper_bound(vec[j].begin(),vec[j].end(),r) - vec[j].begin();
ans += right - left;
// cout<<"ans = "<<ans<<endl;
}
}
else
{
try(i,x,r)
{
register int j = (he[i] - a[x] % k + k) % k;
int right = std::upper_bound(vec[j].begin(),vec[j].end(),x-1) - vec[j].begin();
int left = std::lower_bound(vec[j].begin(),vec[j].end(),l-1) - vec[j].begin();
ans += right - left;
// cout<<"ans = "<<ans<<endl;
}
}
}
int l[maxn],r[maxn];
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get<signed>(); k = get<signed>();
try(i,1,n) a[i] = get<signed>(),he[i] = (he[i-1] + a[i]) % k;
try(i,1,n)
{
while(tot and a[i] >= a[st[tot]]) r[st[tot]] = i - 1,tot--;
l[i] = st[tot] + 1;
st[++tot] = i;
}
while(tot) r[st[tot--]] = n;
// try(i,1,n) cout<<"l[i] = "<<l[i]<<" r[i] = "<<r[i]<<endl;
vec[0].push_back(0);
try(i,1,n) vec[he[i]%k].push_back(i);
try(i,1,n) gan(i,l[i],r[i]);
cout<<ans - n<<endl;
return 0;
}
}
signed main() {return xin::main();}

T2:

这个题其实式子一眼看出。

然而就是打不对。。。

因为我们还有一个操作: 就是约分。

这个才是最毒瘤的地方。。。

本来我们计算出来值之后乘上一个 \(inv\) 就行了。

但是我们要约分。。。。

不能直接取模,因为是分数。。。。

因为答案的式子是:

\[\frac {A_{2^n}^{m}} {2^{nm}}
\]

然后可以发现下面的式子当中约数只有 \(2\)。

所以直接搞 \(2\) 就行了。

然后对于 \(2^n\leqm\) 的情况直接计算并输出两个分母就行了。

#include<bits/stdc++.h>
using std::cout; using std::endl;
#define debug cout<<"debug"<<endl;
#define int long long
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
int eat1; FILE *eat2; char buf[1<<20],*p1 = buf,*p2 = buf;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
template<class type>inline type get()
{
type s = 0,f = 1; register char ch = gc();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io; static const int maxn = 2e6+10,maxb = 110,inf = 0x7f7f7f7f,mod = 1e6+3;
#define try(i,a,b) for(register int i=a;i<=b;++i)
#define throw(i,a,b) for(register int i=a;i>=b;--i)
typedef long long ll;
namespace xin
{
inline int ksm(int x,int y)
{
register int ret = 1;
while(y)
{
if(y & 1) ret = ret * x % mod;
x = x * x % mod;y >>= 1;
}
return ret % mod;
}
int n,m;
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
std::cin>>n>>m;
n = n % (mod - 1);
int ci = 65,fj = 0,pos = 1;
while(ci--)
{
pos <<= 1;
if(pos >= m) break;
fj = (fj + (m - 1) / pos) % (mod - 1);
}
int inv = ksm(ksm(2,fj),mod-2);
int ms = ksm(2,n);
int fm = ksm(ms,(m-1) % (mod - 1)) * inv % mod;
if(m <= mod)
{
int fz = inv;
try(i,1,m-1)
fz = fz*(ms-i+mod)%mod;
fz = (fm - fz + mod) % mod;
cout<<fz<<' '<<fm<<endl;
}
else cout<<fm<<' '<<fm<<endl;
return 0;
}
}
signed main() {return xin::main();}

T3:

大贪心

然而并不好想出。

我猜你们在考场上都是写了 \(1000\) 多个 \(if\)。

然后一个一个手造样例。。。

然而只能拿到 \(10pts\)。

一看全都判成 \(-1\) 了。

正解其实是用两个 \(class\)

一个里面是 \(up\) 表示最大的。

然后一个里面是 \(down\) 装上最小的。

这样就行了。

之后算出来的 \(up\) 和 \(down\) 再去反向模拟算答案。

然后愉快骗过\(special\;judge\)。

愉快 \(AC\)

细节见代码:

#include<bits/stdc++.h>
using std::cout; using std::endl;
#define debug cout<<"debug"<<endl;
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
int eat1; FILE *eat2; char buf[1<<20],*p1 = buf,*p2 = buf;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
template<class type>inline type get()
{
type s = 0,f = 1; register char ch = gc();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io; static const int maxn = 2e6+10,maxb = 110,inf = 0x7f7f7f7f;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
typedef long long ll;
namespace xin
{
class xin_data
{
public:
int val,len;
xin_data(){}
xin_data(int val,int len):val(val),len(len){}
}up[maxn],down[maxn];
int a[maxn],ans[maxn],n,he[maxn];
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get<signed>();
try(i,1,n) a[i] = get<signed>();
a[1] = 1; up[1] = down[1] = xin_data(1,1);
try(i,2,n)
{
up[i] = xin_data(up[i-1].val,up[i-1].len+1);
down[i] = xin_data(down[i-1].val,down[i-1].len+1);
if(up[i].len > 2)
{
up[i].val ++;
up[i].len = 1;
}
if(down[i].len > 5)
{
down[i].val ++;
down[i].len = 1;
}
if(a[i])
{
if(up[i].val == a[i]) up[i].len = std::min(up[i].len,2);
if(up[i].val > a[i]) up[i] = xin_data(a[i],2);
if(down[i].val < a[i]) down[i] = xin_data(a[i],1);
if(up[i].val < a[i] or down[i].val > a[i]) {cout<<-1<<endl; return 0;}
}
}
if(up[n].len == 1) up[n] = xin_data(up[n-1].val,up[n-1].len+1); ans[n] = up[n].val;
cout<<up[n].val<<endl;
he[a[n]] = 1;
throw(i,n-1,0)
{
if(a[i]) ans[i] = a[i];
else
{
register int zhuan = std::min(ans[i+1],up[i].val);
if(he[zhuan] == 5) zhuan --;
ans[i] = zhuan;
}
he[ans[i]] ++;
}
try(i,1,n) printf("%d ",ans[i]);
return 0;
}
}
signed main() {return xin::main();}

总之,尽力想出能想出的所有。

[考试总结]noip模拟12的更多相关文章

  1. noip模拟12[简单的区间·简单的玄学·简单的填数]

    noip模拟12 solutions 这次考试靠的还是比较好的,但是还是有不好的地方, 为啥嘞??因为我觉得我排列组合好像白学了诶,文化课都忘记了 正难则反!!!!!!!! 害没关系啦,一共拿到了\( ...

  2. 6.17考试总结(NOIP模拟8)[星际旅行·砍树·超级树·求和]

    6.17考试总结(NOIP模拟8) 背景 考得不咋样,有一个非常遗憾的地方:最后一题少取膜了,\(100pts->40pts\),改了这么多年的错还是头一回看见以下的情景... T1星际旅行 前 ...

  3. 5.23考试总结(NOIP模拟2)

    5.23考试总结(NOIP模拟2) 洛谷题单 看第一题第一眼,不好打呀;看第一题样例又一眼,诶,我直接一手小阶乘走人 然后就急忙去干T2T3了 后来考完一看,只有\(T1\)骗到了\(15pts\)[ ...

  4. 5.22考试总结(NOIP模拟1)

    5.22考试总结(NOIP模拟1) 改题记录 T1 序列 题解 暴力思路很好想,分数也很好想\(QAQ\) (反正我只拿了5pts) 正解的话: 先用欧拉筛把1-n的素数筛出来 void get_Pr ...

  5. 2021.9.17考试总结[NOIP模拟55]

    有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...

  6. [考试总结]noip模拟23

    因为考试过多,所以学校的博客就暂时咕掉了,放到家里来写 不过话说,vscode的markdown编辑器还是真的很好用 先把 \(noip\) 模拟 \(23\) 的总结写了吧.. 俗话说:" ...

  7. 2021.9.12考试总结[NOIP模拟51]

    T1 茅山道术 仔细观察发现对于每个点只考虑它前面第一个与它颜色相同的点即可. 又仔细观察发现对一段区间染色后以这个区间内点为端点的区间不能染色. 于是对区间右端点而言,区间染色的贡献为遍历到区间左端 ...

  8. 2021.8.12考试总结[NOIP模拟37]

    T1 数列 考场上切掉的简单题. $a$,$b$与数列中数的正负值对答案无关.全当作正数计算即可. $exgcd$解未知数系数为$a$,$b$,加和为$gcd(a,b)$的不定方程组,再枚举每个数.如 ...

  9. 2021.10.12考试总结[NOIP模拟75]

    T1 如何优雅的送分 考虑式子的实际意义.\(2^{f_n}\)实际上就是枚举\(n\)质因子的子集.令\(k\)为这个子集中数的乘积,就可以将式子转化为枚举\(k\),计算\(k\)的贡献. 不难得 ...

随机推荐

  1. 徒手用 Go 写个 Redis 服务器(Godis)

    作者:HDT3213 今天给大家带来的开源项目是 Godis:一个用 Go 语言实现的 Redis 服务器.支持: 5 种数据结构(string.list.hash.set.sortedset) 自动 ...

  2. 【NX二次开发】NX对象类型及基本操作

    说明:NX中的所有对象都是通过唯一的tag_t值进行标识的,这些对象大致可以分为部件对象.UF对象.表达式.链表对象和属性对象等. 部件对象的操作: 基本操作函数: 1. UF_PART_new()  ...

  3. 创建react项目并集成eslint/prettier/commit-lint

    创建 react 项目 npx create-react-app jira-new --template typescript 如果不想使用 TS,而要用 JS 的话,则删除 -template ty ...

  4. React 并发功能体验-前端的并发模式已经到来。

    React 是一个开源 JavaScript 库,开发人员使用它来创建基于 Web 和移动的应用程序,并且支持构建交互式用户界面和 UI 组件.React 是由 Facebook 软件工程师 Jord ...

  5. SpringBoot缓存管理(一) 默认缓存管理

    前言 Spring框架支持透明地向应用程序添加缓存对缓存进行管理,其管理缓存的核心是将缓存应用于操作数据的方法(包括增删查改等),从而减少操作数据的执行次数(主要是查询,直接从缓存中读取数据),同时不 ...

  6. 教你几招HASH表查找的方法

    摘要:根据设定的哈希函数 H(key) 和所选中的处理冲突的方法,将一组关键字映象到一个有限的.地址连续的地址集 (区间) 上,并以关键字在地址集中的"象"作为相应记录在表中的存储 ...

  7. Quartz和Spring Task定时任务的简单应用和比较

    看了两个项目,一个用的是Quartz写的定时器,一个是使用spring的task写的,网上看了2篇文章,写的比较清楚,这里做一下留存 链接一.菠萝大象:http://www.blogjava.net/ ...

  8. phpCOW机制(写时复制)

    写时复制(Copy-on-Write,也缩写为COW),顾名思义,就是在写入时才真正复制一份内存进行修改. COW最早应用在*nix系统中对线程与内存使用的优化,后面广泛的被使用在各种编程语言中,如C ...

  9. ubuntu16.04上编译android的可执行文件并调用本地so库

    前言: 找了蛮多资料的,发现目前实现的编译方式大致就两种,一种是直接使用android源码中的编译工具链,另一种就是使用独立的交叉编译工具链,第二种我还在实现中,配置步骤挺多的 ,第一种实现方式挺方便 ...

  10. 嵌入式Linux会议LinuxCon欧洲的时间表公布

    From: http://linuxgizmos.com/embedded-linux-conference-and-linuxcon-europe-schedules-posted/ Linux基金 ...