跳到正文

个人记录

NOIP2026前

Swordmaker约 37 分钟
原文

这是 2026年11月19日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年11月16日
收录
2026年11月19日
更新
2026年11月20日
篇幅
约 37 分钟

版本

  1. v2当前
  2. v1

2026.11.16

考的是洛谷的NOIP模拟赛。

T1

P17877

需要维护一大坨的线段树,场上想出了正解并花了 3.5h 实现,由于大样例太水导致我的 pushdown 写出了这坨答辩而不自知:

C++
inline void pushdown(int x){
	if(tree[x].cov!=-1){
      tree[x<<1].cov=tree[x<<1|1].cov=
      tree[x<<1].val=tree[x<<1|1].val=tree[x].cov;
      tree[x].cov=-1;
	}
}

赛后发现乘上区间长度就 AC 了,痛失场蓝。

(这坨史有 70pts,lg 拿脚造的数据)

T2

P17878

赛时什么都没打。

发现这个东西是可以二分答案的,我们不妨去二分这个中位数。

直接维护连通块是很困难的,这里给出一个很厉害的定义:

C++
pii dp[N][2];
//dp[i][j]表示以i为根的子树,子树内连通块的奇偶性为j时,当前的权值和以及>=limit的连通块数量差 

然后要依次讨论删不删 (u,v)(u,v) 这条边,以及这么做会对子树造成多大的贡献即可。

其余部分见题解。

T3

P17879

赛时没打,赛后补了。

我们发现对于一个下标 ii,如果 ii 之前的数都不大于 ii 上的元素,且 ii 之后的数都不小于 ii 上之后的元素,则 ii 位置一定会被所有的最长不下降子序列选到。

先考虑填上 bi>0b_i>0 的位置。再用一些 bi≤0b_i \le 0 的位置和不满足条件的 bi>0b_i>0 的位置组成逆序对。发现剩下 bi>0b_i>0 的位置中 aia_i 是单调不降的,于是任意一个 bi≤0b_i \le 0 的位置对应能匹配成逆序对的位置是一个区间。

然后就是求最大的区间并,设 dpidp_i 表示考虑前 ii 个元素是区间并和的最大值,再维护 bib_i 的前缀和,则有:

dpi=max⁡(dpi−1,si+val+max⁡l−1≤j≤i−1dpj−sj)dp_i=\max(dp_{i-1},s_i+val+\max_{l-1 \le j \le i-1}dp_j-s_j)

线段树维护最大的 dpi−sidp_i-s_i。

T4

P17880

场上打了 4pts 的暴力。

2026.11.17

打的超级烂,建议拿省四。

首先是没有想到将军的比赛会难度乱序,所以花了很长时间在一个大概率有紫的 T1 上面,一开始想的很简单,认为随便做一下就行了,然后发现有点假,开始想 Top Cluster,点分治,换根 DP 之类乱七八糟的东西。

最后想到了一个假的 O(n)O(n) 做法,但是在测大样例时发现只有几个过不去。于是我没有仔细思考自己做法的正确性,想要修补一下,结果修了三个多小时还没修出来。最后只能直接扔了。

这导致我都完全没怎么思考后三题,T2 虽然只花几秒就想到和二分以及因数有关,但是这他妈是道交互,然后就没时间调。

T3 看见是 DP 直接不知所措,乱写了一个比较对的式子,结果连 n=2n=2 都过不去。然后又扔了。赛后发现是生成函数,那咋办。然后 TobyHu 给我讲了个 O(nm)O(nm) 的做法,吓哭了。

(这是怎么赛后有 10pts 的)

看了眼 T4 马上想到用平衡树来维护,结果由于时间不够中间有些处理太乱了,然后也没什么分。

状态很差,警钟长鸣。

T1

给定一棵树,定义点对 (u,v)(u,v) 的价值 f(u,v)f(u,v) 如下:

在 uu 到 vv 的简单路径上,若 uu 为最大值且 vv 为最小值,则价值为 ava_v,否则为 00。

对于每个点 uu,求 ∑u≠vf(u,v)\sum_{u \ne v} f(u,v)。

题解不像人:

完全不会笛卡尔树,布丁。

T2

q=9q=9 诗人啊

来你告诉我什么叫“首先这个东西询问的是 Z 函数中 ZiZ_i 的值”。

我不会 Z 函数。

不过题还是可以订的:

我们发现可以 O(1)O(1) 来 check 一个分割长度是否可能,然后又可以知道只有 nn 的因数是有用的,因此可以尝试在这上面做文章。

发现这个 99 很特殊,大胆猜测是一坨质因子的乘积。

然后发现前几个小的质因子的乘积小于 nn,发现可以对每个质因子的幂次进行二分,总次数小于 99 次。

code
C++
#include"period.h"
int solve(int n,int q){
	int ans=1,pre=n;
	for(int i=2;i<=n;i++){
		if(n%i) continue;
		int l=1,r=0,res=1;
		while(!(n%i)) n/=i,r++;
		while(l<=r){
			int mid=(l+r)>>1,p=1;
			for(int j=1;j<=mid;j++) p*=i;
			if(query(pre/p)+pre/p==pre) res=p,l=mid+1;
			else r=mid-1;
		}
		ans*=res;
	}
	return ans;
}

T3

题解生成函数没智力。

订了 TobyHu 的 O(m2log⁡m)O(m^2 \log m)。

code
C++
#include<bits/stdc++.h>
#define int long long 
namespace EVA{
	inline int read(){
		int x=0,f=1;
		char c=getchar();
		while(c<'0'||c>'9'){
			if(c=='-') f^=1;
			c=getchar();
		}
		while(c>='0'&&c<='9'){
			x=(x<<3)+(x<<1)+(c^48);
			c=getchar();
		}
		return f?x:~x+1;
	}
	inline void write(int x){
		if(x<0) x=~x+1,putchar('-');
		if(x>9) write(x/10);
		putchar(x%10^48);
	}
	inline void spaceput(int x){
		write(x);putchar(' ');
	}
	inline void output(int x){
		write(x);putchar('\n');
	}
} 
using namespace EVA;
using namespace std;
const int N=1e4+5;
const int mod=1e9+7;
int n,m;
int a[N],dp[N],g[N],c[N],inv[N];
inline void init(){
	inv[1]=1;
	for(int i=2;i<=m;i++) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
}
signed main(){
	n=read(),m=read();init();
	for(int i=1;i<=n;i++) a[i]=read();
	dp[0]=c[0]=1;
	for(int i=1;i<=m;i++){
		if(!a[i]) continue;
		for(int j=1;j<=m/i;j++) c[j]=c[j-1]*(a[i]+j-1)%mod*inv[j]%mod;
		for(int j=0;j<=m/i;j++){
			for(int k=0;k+i*j<=m;k++) g[i*j+k]=(g[i*j+k]+c[j]*dp[k]%mod)%mod;
		} 
		for(int j=0;j<=m;j++) dp[j]=g[j],g[j]=0;
	}
	for(int i=1;i<=m;i++) spaceput(dp[i]);
	return 0;
}

T4

image.png

image.png

这种题都没切。

请问我赛场上在干什么。

不过这个特征值等于区间长度减众数的 trick 有点不好证扔给了翁陆恒让他帮我证。

code
C++
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/exception.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/list_update_policy.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
//#define int long long 
namespace EVA{
	inline int read(){
		int x=0,f=1;
		char c=getchar();
		while(c<'0'||c>'9'){
			if(c=='-') f^=1;
			c=getchar();
		}
		while(c>='0'&&c<='9'){
			x=(x<<3)+(x<<1)+(c^48);
			c=getchar();
		}
		return f?x:~x+1;
	}
	inline void write(int x){
		if(x<0) x=~x+1,putchar('-');
		if(x>9) write(x/10);
		putchar(x%10^48);
	}
	inline void spaceput(int x){
		write(x);putchar(' ');
	}
	inline void output(int x){
		write(x);putchar('\n');
	}
} 
using namespace EVA;
using namespace std;
using namespace __gnu_pbds;
const int N=2e5+5;
//const int inf=1e18;
int n,q;
int a[N];
multiset<int> s;
cc_hash_table<int,int> ct;
#define IT multiset<int>::iterator
inline void check(){
	auto it=s.rbegin();
	output(n-*it);
}
signed main(){
	n=read(),q=read();
	for(int i=1;i<=n;i++) a[i]=read(),ct[a[i]]++;
	for(auto v:ct) s.insert(v.second);
	check();
	for(int i=1;i<=q;i++){
		int p,x;p=read(),x=read();
		int res=ct[a[p]];
		IT it=s.lower_bound(res);
		s.erase(it);
		if(ct[a[p]]!=1) ct[a[p]]--,s.insert(ct[a[p]]);
		else ct.erase(a[p]); 
		if(ct.find(x)==ct.end()){
			s.insert(1);ct[x]=1;
		}
		else{
			res=ct[x];ct[x]++;
			it=s.lower_bound(res);
			s.erase(it);s.insert(ct[x]);
		}
		check();a[p]=x;
	}
	return 0;
}

笑点解析:我正在思考用 cc_hash_table 还是 gp_hash_table 更快的时候,TobyHu 信誓旦旦地和我说 gp_hash_table 更快,结果就他的 gp_hash_table 会 TLE,其他的 map,unordered_map,cc_hash_table 都能过,太不堪了。

2026.11.18

自由练习,VP 了 ZR Day 8。

ZR3729.看门狗

image.png

区间 chkmax 线段树模板,随便写写就切了。

code
C++
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define ull unsigned long long
#define i128 __int128
#ifdef __linux__
//#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define CK_TM cerr<<'\n'<<1.0*fabs(&ENDM-&STARTM)/(1024*1024)<<"MB"<<" "<<1.0*clock()/CLOCKS_PER_SEC*1000<<"ms"<<'\n';
char buf[1<<25],*p1,*p2;
#define getchar() ((p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<25,stdin))?EOF:*p1++)
#define vector basic_string
#define pq priority_queue
#define mkpr make_pair
#define pii pair<int,int>
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define sz(h) (int)h.size()
#define popc(x) __builtin_popcount(x)
bool STARTM;
constexpr double eps=1e-10;
constexpr int i_inf=1e9;
constexpr ll ll_inf=1e18;
namespace AyanamiRei{
	inline int read(){
		int x=0,f=1;char c=getchar();
		while(c<'0'||c>'9') {if(c=='-') f^=1;c=getchar();}
		while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
		return f?x:~x+1;
	}
}namespace SoryuAsukaRangure{
	inline void write(int x){
		if(x<0) x=~x+1,putchar('-');
		if(x>9) write(x/10);
		return putchar(x%10^48),void();
	}
}namespace AyanamiYue{
	inline void spaceput(int x){
		SoryuAsukaRangure::write(x);putchar(' ');
	}
}namespace IkariYue{
	inline void output(int x){
		SoryuAsukaRangure::write(x);putchar('\n');
	}
}namespace IkariShinji{
	inline int max(int x,int y){
		return x>y?x:y;
	}
}namespace NagisaKaworu{
	inline int min(int x,int y){
		return x<y?x:y;
	}
}namespace MariMakinamiIllustious{
	inline double MAX(double x,double y){
		return x-y>eps?x:y;
	}
}namespace ShikinamiAsukaRangure{
	inline double MIN(double x,double y){
		return y-x>eps?x:y;
	}
}
using namespace std;
using namespace AyanamiRei;
using namespace SoryuAsukaRangure;
using namespace AyanamiYue;
using namespace IkariYue;
using namespace IkariShinji;
using namespace NagisaKaworu;
using namespace MariMakinamiIllustious;
using namespace ShikinamiAsukaRangure;
constexpr int N=1e6+5;
constexpr int the_birthday_of_Asuka=20011204;
constexpr int the_birthday_of_Ayanami=20010330;
mt19937 Asuka(the_birthday_of_Asuka+time(0));
mt19937 Ayanami(the_birthday_of_Ayanami+time(0));
int n,tot;
int a[N],cur[N];
vi eva[N];
bitset<N> vis;
struct smt{
	int mx,tag;
}tree[N<<2];
namespace SMT{
	inline void pushup(int x){
		tree[x].mx=max(tree[x<<1].mx,tree[x<<1|1].mx);
	}
	inline void pushdown(int x){
		if(tree[x].tag){
			tree[x<<1].tag=max(tree[x<<1].tag,tree[x].tag);
			tree[x<<1|1].tag=max(tree[x<<1|1].tag,tree[x].tag);	
			tree[x<<1].mx=max(tree[x<<1].mx,tree[x].tag);
			tree[x<<1|1].mx=max(tree[x<<1|1].mx,tree[x].tag);
			tree[x].tag=0;
		}
	}
	inline void build(int x,int l,int r){
		if(l==r) return tree[x].mx=-1,void();
		int mid=(l+r)>>1;
		build(x<<1,l,mid),build(x<<1|1,mid+1,r);
		pushup(x);
	}
	inline void modify(int x,int v,int L,int R,int l,int r){
		if(L<=l&&r<=R){
			tree[x].tag=max(tree[x].tag,v);
			tree[x].mx=max(tree[x].mx,v);
			return;
		}
		int mid=(l+r)>>1;pushdown(x);
		if(L<=mid) modify(x<<1,v,L,R,l,mid);
		if(mid<R) modify(x<<1|1,v,L,R,mid+1,r);
		pushup(x);
	}
	inline int query(int x,int L,int R,int l,int r){
		if(L<=l&&r<=R) return tree[x].mx;
		int mid=(l+r)>>1,res=-1;pushdown(x);
		if(L<=mid) res=max(res,query(x<<1,L,R,l,mid));
		if(mid<R) res=max(res,query(x<<1|1,L,R,mid+1,r));
		return res;
	}
}
bool ENDM;
signed main(){
//	system("fc patience.out ex_patience6.out /w");
//	freopen("ex_patience6.in","r",stdin);
//	freopen("patience.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		if(!vis[a[i]]) cur[++tot]=a[i];
		vis[a[i]]=1;eva[a[i]].pb(i);
	}
	if(vis.count()==1){
		for(int i=1;i<=n;i++) spaceput(a[i]);
		return 0;
	}
	sort(cur+1,cur+tot+1);
	SMT::build(1,1,n);
	for(int i=1;i<=tot;i++){
		sort(eva[cur[i]].begin(),eva[cur[i]].end());
		int len=i_inf,C=-i_inf;
		for(int j=0;j<sz(eva[cur[i]]);j++){
//			int A=eva[cur[i]][j],B=n-eva[cur[i]][j]+1,C=-i_inf;
			if(j) C=max(C,abs(eva[cur[i]][j]-eva[cur[i]][j-1]));
//			len=min(len,min(C,max(A,B)));
		}
		int A=eva[cur[i]][0],B=n-eva[cur[i]][sz(eva[cur[i]])-1]+1;
		len=min(len,max(C,max(A,B)));
//		cerr<<cur[i]<<" "<<len<<'\n';
		SMT::modify(1,cur[i],len,n,1,n);
	}
	for(int i=1;i<=n;i++) spaceput(SMT::query(1,i,i,1,n));
//	CK_TM;
	return 0;
}

ZR3730.百年好合/P14347

很厉害的题。

我的题解

P5464

深刻。

你发现这个问题等价于选出若干条线段,使得集合中任意三条线段无交的数量。

树状数组维护即可,复杂度 O(n2log⁡n)O(n^2 \log n)。

P6032

双指针。

ZR3732.合唱/P9293

这题神了。

没订完。

ZR3731.墨山/P14382

不是题。

2026.11.19

ZR Day 18

10+25+25+2010 + 25 + 25 + 20,建议退役

T1

image.png

赛场上的想法不太自然,既维护了左边第一个 S(1,pos)≥S(pos+1,i)S(1,pos) \ge S(pos+1,i) 的位置,又维护了右边第一个位置,导致式子没有推完。

看看题解是怎么处理这个东西的:

image.png

感觉 *2300 左右吧,有点要脑子。

code
C++
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define i128 __int128
#ifdef __linux__
//#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define CK_TM cerr<<'\n'<<1.0*fabs(&ENDM-&STARTM)/(1024*1024)<<"MB"<<" "<<1.0*clock()/CLOCKS_PER_SEC*1000<<"ms"<<'\n';
char buf[1<<25],*p1,*p2;
#define getchar() ((p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<25,stdin))?EOF:*p1++)
#define vector basic_string
#define pq priority_queue
#define mkpr make_pair
#define pii pair<int,int>
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define sz(h) (int)h.size()
#define popc(x) __builtin_popcount(x)
bool STARTM;
constexpr double eps=1e-10;
constexpr int i_inf=1e9;
constexpr ll ll_inf=1e18;
namespace AyanamiRei{
	inline int read(){
		int x=0,f=1;char c=getchar();
		while(c<'0'||c>'9') {if(c=='-') f^=1;c=getchar();}
		while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
		return f?x:~x+1;
	}
}namespace SoryuAsukaRangure{
	inline void write(int x){
		if(x<0) x=~x+1,putchar('-');
		if(x>9) write(x/10);
		return putchar(x%10^48),void();
	}
}namespace AyanamiYue{
	inline void spaceput(int x){
		SoryuAsukaRangure::write(x);putchar(' ');
	}
}namespace IkariYue{
	inline void output(int x){
		SoryuAsukaRangure::write(x);putchar('\n');
	}
}namespace IkariShinji{
	inline int max(int x,int y){
		return x>y?x:y;
	}
}namespace NagisaKaworu{
	inline int min(int x,int y){
		return x<y?x:y;
	}
}namespace MariMakinamiIllustious{
	inline double MAX(double x,double y){
		return x-y>eps?x:y;
	}
}namespace ShikinamiAsukaRangure{
	inline double MIN(double x,double y){
		return y-x>eps?x:y;
	}
}
using namespace std;
using namespace AyanamiRei;
using namespace SoryuAsukaRangure;
using namespace AyanamiYue;
using namespace IkariYue;
using namespace IkariShinji;
using namespace NagisaKaworu;
using namespace MariMakinamiIllustious;
using namespace ShikinamiAsukaRangure;
constexpr int N=1e6+5;
constexpr int the_birthday_of_Asuka=20011204;
constexpr int the_birthday_of_Ayanami=20010330;
mt19937 Asuka(the_birthday_of_Asuka+time(0));
mt19937 Ayanami(the_birthday_of_Ayanami+time(0));
int n,mod;
int pos[N],r[N],dp[N],pw2[N];
inline int C(int l,int r){
	return (r-l+1)*(r+l)/2;
}
int tree[N<<2];
namespace SMT{
	inline void pushup(int x){
		tree[x]=tree[x<<1]+tree[x<<1|1];
	}
	inline void update(int x,int p,int v,int l,int r){
		if(l==r&&l==p) return tree[x]=v,void();
		int mid=(l+r)>>1;
		if(p<=mid) update(x<<1,p,v,l,mid);
		else update(x<<1|1,p,v,mid+1,r);
		pushup(x);
	}
	inline int query(int x,int L,int R,int l,int r){
		if(L>r||L>R||l>R) return 0; 
		if(L<=l&&r<=R) return tree[x];
		int mid=(l+r)>>1,res=0;
		if(L<=mid) res+=query(x<<1,L,R,l,mid);
		if(mid<R) res+=query(x<<1|1,L,R,mid+1,r);
		return res;
	}
}
bool ENDM;
signed main(){
	n=read(),mod=read();
	if(mod==2){
		for(int i=1;i<=n;i++) spaceput(0);
		return 0;
	}
	pw2[0]=1;
	for(int i=1;i<=n;i++) pw2[i]=pw2[i-1]*2%mod;
	pos[1]=1;
	for(int i=2;i<=n;i++){
		pos[i]=pos[i-1];
		while(pos[i]<i&&C(pos[i]+1,i)>C(1,pos[i])) pos[i]++;
	}
	r[1]=1;
	for(int i=2;i<=n;i++){
		r[i]=r[i-1];
		while(r[i]<n&&pos[r[i]+1]<=i) r[i]++;
	}
	dp[n]=2%mod;SMT::update(1,n,dp[n],1,n);
	for(int i=n-1;i>=1;i--){
		dp[i]=(dp[i]+SMT::query(1,i+1,r[i],1,n))%mod;
		SMT::update(1,i,dp[i],1,n);
	}
	for(int i=1;i<=n;i++) spaceput(dp[i]*pw2[pos[i]-1]%mod);
	CK_TM;
	return 0;
}

T2

唯二像题的题。

image.png

image.png

注意到本题的核心是定义出这两个东西:

C++
//p[i]=f(p[i-1],i)为从0一路向上挑战的结果
//nxt[i]表示p[i]+1与p[i+1]重合的位置

我真的觉得这个 pp 数组和 nxtnxt 数组的定义非常巧妙,这样就可以把这道题转化为一个分讨数学题了。

code
C++
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define i128 __int128
#ifdef __linux__
//#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define CK_TM cerr<<'\n'<<1.0*fabs(&ENDM-&STARTM)/(1024*1024)<<"MB"<<" "<<1.0*clock()/CLOCKS_PER_SEC*1000<<"ms"<<'\n';
char buf[1<<25],*p1,*p2;
#define getchar() ((p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<25,stdin))?EOF:*p1++)
#define vector basic_string
#define pq priority_queue
#define mkpr make_pair
#define pii pair<int,int>
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define sz(h) (int)h.size()
#define popc(x) __builtin_popcount(x)
bool STARTM;
constexpr double eps=1e-10;
constexpr int i_inf=1e9;
constexpr ll ll_inf=1e18;
namespace AyanamiRei{
	inline int read(){
		int x=0,f=1;char c=getchar();
		while(c<'0'||c>'9') {if(c=='-') f^=1;c=getchar();}
		while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
		return f?x:~x+1;
	}
}namespace SoryuAsukaRangure{
	inline void write(int x){
		if(x<0) x=~x+1,putchar('-');
		if(x>9) write(x/10);
		return putchar(x%10^48),void();
	}
}namespace AyanamiYue{
	inline void spaceput(int x){
		SoryuAsukaRangure::write(x);putchar(' ');
	}
}namespace IkariYue{
	inline void output(int x){
		SoryuAsukaRangure::write(x);putchar('\n');
	}
}namespace IkariShinji{
	inline int max(int x,int y){
		return x>y?x:y;
	}
}namespace NagisaKaworu{
	inline int min(int x,int y){
		return x<y?x:y;
	}
}namespace MariMakinamiIllustious{
	inline double MAX(double x,double y){
		return x-y>eps?x:y;
	}
}namespace ShikinamiAsukaRangure{
	inline double MIN(double x,double y){
		return y-x>eps?x:y;
	}
}
using namespace std;
using namespace AyanamiRei;
using namespace SoryuAsukaRangure;
using namespace AyanamiYue;
using namespace IkariYue;
using namespace IkariShinji;
using namespace NagisaKaworu;
using namespace MariMakinamiIllustious;
using namespace ShikinamiAsukaRangure;
constexpr int N=2e5+5;
constexpr int the_birthday_of_Asuka=20011204;
constexpr int the_birthday_of_Ayanami=20010330;
mt19937 Asuka(the_birthday_of_Asuka+time(0));
mt19937 Ayanami(the_birthday_of_Ayanami+time(0));
int Case,n,q;
int a[N],p[N],nxt[N];
//p[i]=f(p[i-1],i)为从0一路向上挑战的结果
//nxt[i]表示p[i]+1与p[i+1]重合的位置
bool ENDM;
signed main(){
	Case=read(),n=read(),q=read();
	for(int i=1;i<=n;i++) a[i]=read();
	p[0]=0;nxt[n]=n+1;
	for(int i=1;i<=n;i++) p[i]=(p[i-1]+a[i]+1)/2;
	for(int i=n-1;i>=0;i--){
		if(p[i+1]==(p[i]+a[i+1]+2)/2) nxt[i]=i+1;
		else nxt[i]=nxt[i+1];
	}
	while(q--){
		int x,y,now;x=read(),y=read();
		now=x;y=n-y+1;
		if(x>=a[y]){
			output(0);continue;
		}
		int pos=upper_bound(a+1,a+n+1,x)-a;
		while(pos<=y&&x-p[pos-1]>1){
			x=(x+a[pos]+1)/2;pos++;
		}
		if(pos<=y){
			if(x==p[pos-1]||nxt[pos-1]<=y) x=p[y];
			else x=p[y]+1;
		}
		output(x-now);
	}
	CK_TM;
	return 0;
}

T3

原题

image.png

image.png

image.png

image.png

image.png

叉姐的题,太厉害了!