NOIP2026前
Swordmaker · · 个人记录
2026.11.16
洛谷 NOIP 模拟赛。
T1
P17877
需要维护一大坨的线段树,场上想出了正解并花了 3.5h 实现,由于大样例太水导致我的 pushdown 写出了这坨答辩而不自知:
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 拿脚造的数据)
dif:5/11
T2
P17878
赛时什么都没打。
发现这个东西是可以二分答案的,我们不妨去二分这个中位数。
直接维护连通块是很困难的,这里给出一个很厉害的定义:
pii dp[N][2];
//dp[i][j]表示以i为根的子树,子树内连通块的奇偶性为j时,当前的权值和以及>=limit的连通块数量差
然后要依次讨论删不删
其余部分见题解。
dif:5.5/11
T3
P17879
赛时没打,赛后补了。
我们发现对于一个下标
先考虑填上
然后就是求最大的区间并,设
线段树维护最大的
dif:6.5/11
T4
P17880
场上打了 4pts 的暴力。
dif:7.5/11
2026.11.17
打的超级烂,建议拿省四。
首先是没有想到将军的比赛会难度乱序,所以花了很长时间在一个大概率有紫的 T1 上面,一开始想的很简单,认为随便做一下就行了,然后发现有点假,开始想 Top Cluster,点分治,换根 DP 之类乱七八糟的东西。
最后想到了一个假的
这导致我都完全没怎么思考后三题,T2 虽然只花几秒就想到和二分以及因数有关,但是这他妈是道交互,然后就没时间调。
T3 看见是 DP 直接不知所措,乱写了一个比较对的式子,结果连 那咋办。然后 TobyHu 给我讲了个
(这是怎么赛后有 10pts 的)
看了眼 T4 马上想到用平衡树来维护,结果由于时间不够中间有些处理太乱了,然后也没什么分。
状态很差,警钟长鸣。
T1
给定一棵树,定义点对
在
对于每个点
题解不像人:
完全不会笛卡尔树,布丁。
dif:6/11
T2
来你告诉我什么叫“首先这个东西询问的是 Z 函数中
我不会 Z 函数。
不过题还是可以订的:
我们发现可以
发现这个
然后发现前几个小的质因子的乘积小于
::::info[code]
#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;
}
::::
dif:4/11
T3
题解生成函数没智力。
订了 TobyHu 的
::::info[code]
#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;
}
::::
dif:5.5/11
T4
这种题都没切。
请问我赛场上在干什么。
不过这个特征值等于区间长度减众数的 trick 有点不好证扔给了翁陆恒让他帮我证。
翁陆恒证出来了。
::::info[code]
#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 都能过,太不堪了。
dif:4.25/11
2026.11.18
自由练习,VP 了 ZR Day 8。
ZR3729.看门狗
区间 chkmax 线段树模板,随便写写就切了。
::::info[code]
#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;
}
::::
dif:3/11
ZR3730.百年好合/P14347
很厉害的题。
我的题解
dif:6/11
P5464
深刻。
你发现这个问题等价于选出若干条线段,使得集合中任意三条线段无交的数量。
树状数组维护即可,复杂度
dif:5.5/11
P6032
双指针。
ZR3732.合唱/P9293
这题神了。
没订完。
我草我线段树写错了。
这个东西还是看题解吧,思路太长了说是。
::::info[code]
#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=6e5+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,sum,tot,L;
int ans[N<<1],rk[N],head[N],nxt[N];
vi eva[N];
set<int> s;
inline int manosaba(int Ema,int Hiro){
return rk[Ema]<rk[Hiro];
}
struct smt{
pii mx;
int ct,lazy;
}tree[N<<2];
namespace SMT{
inline void pushup(int x){
tree[x].ct=tree[x<<1].ct+tree[x<<1|1].ct;
tree[x].mx=std::max(tree[x<<1].mx,tree[x<<1|1].mx);
}
inline void pushdown(int x){
if(tree[x].lazy){
tree[x<<1].mx.first+=tree[x].lazy;
tree[x<<1|1].mx.first+=tree[x].lazy;
tree[x<<1].lazy+=tree[x].lazy;
tree[x<<1|1].lazy+=tree[x].lazy;
tree[x].lazy=0;
}
}
inline void build(int x,int l,int r){
if(l==r) return tree[x].mx=mkpr(-i_inf,l),void();
int mid=(l+r)>>1;
build(x<<1,l,mid),build(x<<1|1,mid+1,r);
pushup(x);
}
inline void update(int x,int p,int v,int c,int l,int r){
if(l==r){
tree[x].mx.first=v,tree[x].ct=c;
return;
}
int mid=(l+r)>>1;pushdown(x);
if(p<=mid) update(x<<1,p,v,c,l,mid);
else update(x<<1|1,p,v,c,mid+1,r);
pushup(x);
}
inline void add(int x,int v,int L,int R,int l,int r){
if(L>r||l>R) return;
if(L<=l&&r<=R){
tree[x].lazy+=v,tree[x].mx.first+=v;
return;
}
int mid=(l+r)>>1;pushdown(x);
if(L<=mid) add(x<<1,v,L,R,l,mid);
if(mid<R) add(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>r||l>R||L>R) return 0;
if(L<=l&&r<=R) return tree[x].ct;
int mid=(l+r)>>1,res=0;pushdown(x);
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;
}
}
namespace SET{
inline void rebuild(int v){
SMT::add(1,1,1,v-1,1,tot);
SMT::update(1,v,SMT::query(1,v+1,sum,1,tot)+head[v],1,1,tot);
s.insert(v);
}
inline void sword(int v){
SMT::add(1,-1,1,v-1,1,tot);
SMT::update(1,v,-i_inf,0,1,tot);
s.erase(v);
}
inline int check(int v){
if(s.empty()) return 1;
pii cur=tree[1].mx;
int lim=cur.first,g8c=cur.second,now=lim;
if(lim>v) return 0;
vi del;
while(1){
int f=*s.rbegin();
sword(f),del.pb(f);
ans[now--]=1;
if(f==g8c) break;
}
if(nxt[g8c]) rebuild(nxt[g8c]);
if(check(now)) return 1;
if(nxt[g8c]) sword(nxt[g8c]);
if(lim==v){
for(int i=now+1;i<=lim;i++) ans[i]=0;
for(int e:del) rebuild(e);
return 0;
}
ans[lim+1]=1,ans[now+1]=0;
return check(now+1);
}
}
bool ENDM;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
string w;cin>>w;reverse(w.begin(),w.end());
int len=w.length();L=max(L,len);w=" "+w;
for(int j=1;j<=len;j++){
if(w[j]=='1') eva[j].pb(i),sum++;
}
}
for(int i=1;i<=L;i++){
sort(eva[i].begin(),eva[i].end(),manosaba);
for(int v:eva[i]){
tot++;
nxt[tot]=rk[v];rk[v]=tot;head[tot]=i-1;
}
}
SMT::build(1,1,tot);
for(int i=1;i<=n;i++) SET::rebuild(rk[i]);
SET::check(n+L);int flag=1;
for(int i=L+n;i>=0;i--){
if(ans[i]) write(ans[i]),flag=0;
else if(!flag) write(ans[i]);
}
CK_TM;
return 0;
}
::::
dif:8.5/11
ZR3731.墨山/P14382
不是题。
dif:7.5/11
2026.11.19
ZR Day 18
dif:(8)?
2026.11.20
ZR Day 19
-
v > j$:$dp_{i,v} \leftarrow dp_{i,v} + dp_{i-1,j}
贴一个
::::info[
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) dp[i][j]=0;
}
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
// if(!dp[i-1][j]) continue;
int cnt=0;
for(int k=1;k<=j;k++){//当前填入的数
if(i>=x[k]||j>=y[k]) cnt++;
}
if(cnt>0) dp[i][j]=(dp[i][j]+dp[i-1][j]*(cnt-i+1)%mod)%mod;
for(int k=j+1;k<=n;k++){
if(i>=x[k]||j>=y[k]) dp[i][k]=(dp[i][k]+dp[i-1][j])%mod;
}
}
}
output(dp[n][n]%mod);
::::
然后发现这个东西感觉不怎么可以优化,那咋办
果断查看题解,发现一个非常厉害的性质:
相当深刻。
::::info[code]
#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=5e3+5;
constexpr int mod=998244353;
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,ans;
int x[N],s[N],y[N],c[N],dp[N][N];
bool ENDM;
signed main(){
int T;T=read();
while(T--){
n=read();
for(int i=1;i<=n;i++) x[i]=read();
for(int i=1;i<=n;i++) y[i]=read();
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
dp[i][j]=0;
}
}
for(int i=0;i<=n;i++) dp[0][i]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++) s[j]=c[j]=0;
for(int j=1;j<=n;j++){
if(x[j]>i) c[0]++,c[y[j]]--;
if(x[j]<=i) s[0]++,s[j]--;
else if(y[j]<j) s[y[j]]++,s[j]--;
}
for(int j=1;j<=n;j++) s[j]+=s[j-1],c[j]+=c[j-1];
for(int j=i;j<=n;j++) dp[i][j]=(dp[i-1][j]-dp[i-1][j-1]+mod)%mod*max(0ll,n-i+1-s[j]-c[j])%mod;
for(int j=i;j<=n;j++){
if(x[j]<=i) dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
else if(y[j]<j) dp[i][j]=(dp[i][j]+dp[i-1][j-1]-dp[i-1][y[j]-1]+mod)%mod;
}
for(int j=0;j<i;j++) dp[i][j]=0;
for(int j=i;j<=n;j++) dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
}
output(dp[n][n]%mod);
}
CK_TM;
return 0;
}
::::
dif:6.75/11
P12751
【模板】根号分治
::::info[code]
#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=1e5+3e4;
constexpr int SQN=sqrt(N/2)+1;
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,k,B;
int c[N],s[N][SQN];
bool ENDM;
signed main(){
n=read(),k=read();B=sqrt(n/2);
for(int i=1;i<=k;i++){
int a,l,d;a=read(),l=read(),d=read();
if(d>B) for(int j=1;j<=l;j++) c[a+(j-1)*d]++;
else s[a][d]++,s[a+l*d][d]--;
}
for(int j=1;j<=B;j++){
for(int i=j;i<=n;i++) s[i][j]+=s[i-j][j];
for(int i=1;i<=n;i++) c[i]+=s[i][j];
}
for(int i=1;i<=n;i++) spaceput(c[i]);
CK_TM;
return 0;
}
::::
dif:2.5/11
2026.11.21
自由练习。
P4362
很典但是很难的树形 dp。
设
转移时分为两种情况:
大头不吃
大头吃
::::info[code]
#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=3e2+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,m,k,tot=1;
int head[N],dp[N][N][2],cur[N][2];
//dp[i][j][k]表示对于i号节点为根的树,大头吃了j个果子,且根节点不是/是大头吃的最小难受值
//ans:dp[1][k][1]
struct edge{
int to,val,next;
}e[N<<1];
inline void addedge(int u,int v,int w){
tot++;
e[tot].to=v;
e[tot].val=w;
e[tot].next=head[u];
head[u]=tot;
}
void dfs(int u,int f){
dp[u][0][0]=dp[u][1][1]=0;
for(int i=head[u];i;i=e[i].next){
int v=e[i].to,w=e[i].val;
if(v==f) continue;
dfs(v,u);
for(int j=0;j<=n;j++){
for(int s=0;s<2;s++){
cur[j][s]=dp[u][j][s];
dp[u][j][s]=ll_inf;
}
}
for(int j=0;j<=k;j++){
for(int s=0;s<=j;s++){
dp[u][j][0]=min(dp[u][j][0],min(dp[v][s][0]+cur[j-s][0]+(m==2)*w,dp[v][s][1]+cur[j-s][0]));
dp[u][j][1]=min(dp[u][j][1],min(dp[v][s][1]+cur[j-s][1]+w,dp[v][s][0]+cur[j-s][1]));
}
}
}
}
bool ENDM;
signed main(){
n=read(),m=read(),k=read();
for(int i=1;i<n;i++){
int u,v,w;u=read(),v=read(),w=read();
addedge(u,v,w),addedge(v,u,w);
}
if(n-k<m-1) return write(-1),0;
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int s=0;s<2;s++){
dp[i][j][s]=ll_inf;
}
}
}
dfs(1,0);
write(dp[1][k][1]);
CK_TM;
return 0;
}
::::
dif:5.75/11
P10210/P10144
超级厉害的题。
如果你的思路被锁死在枚举这个二元组,那么很显然至少是
进行思考查看题解,我们发现可以对每对相邻位置作分讨:
转化一下,就是:
发现这个东西有一些性质,可以做非法检验:
容易发现这题是神题。
::::info[code]
#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=5e5+5;
constexpr int LOGN=23;
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;
int lg2[N],a[N],mx[LOGN][N],mn[LOGN][N];
inline int qmax(int l,int r){
int k=lg2[r-l+1];
return max(mx[k][l],mx[k][r-(1<<k)+1]);
}
inline int qmin(int l,int r){
int k=lg2[r-l+1];
return min(mn[k][l],mn[k][r-(1<<k)+1]);
}
bool ENDM;
signed main(){
for(int i=2;i<N;i++) lg2[i]=lg2[i/2]+1;
n=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=2;i<n;i++){
mx[0][i]=-ll_inf;
mn[0][i]=ll_inf;
if(a[i]>=a[i-1]&&a[i]>=a[i+1]) mx[0][i]=a[i]+min(a[i-1],a[i+1]);
if(a[i]<=a[i-1]&&a[i]<=a[i+1]) mn[0][i]=a[i]+max(a[i-1],a[i+1]);
}
for(int j=1;(1<<j)<=n;j++){
for(int i=1;i+(1<<j)-1<=n;i++){
mx[j][i]=max(mx[j-1][i],mx[j-1][i+(1<<(j-1))]);
mn[j][i]=min(mn[j-1][i],mn[j-1][i+(1<<(j-1))]);
}
}
int ans=0;
for(int i=1;i<n;i++){
int l=i+1,r=n,pos=0;
while(l<=r){
int mid=(l+r)>>1;
if(mid-i<=1||qmax(i+1,mid-1)<qmin(i+1,mid-1)) pos=mid,l=mid+1;
else r=mid-1;
}
ans+=pos-i;
}
output(ans);
CK_TM;
return 0;
}
::::
dif:7.5/11
P1441
不会 bitset,预处理后随便 dp 就切了。
dif:-1/11
P14593/CF1601D
做过的最牛逼的思维题。
::::info[提示]
:::info[按什么排序?]
按
- $b_i>a_{i+1}$:交换一定不会少打,可能会多打
- $a_i>b_{i+1}$:无影响
::: :::info[fun fact] 发现这个东西就是邻项交换(exchange argument) ::: ::::
dif:7.75/11
2026.11.22
CF Div 2
惊天一车区,其中我是最傻逼的。
赛时的无效思考/假算太多了,我是奶龙。
A
注意到奇数一定赢,偶数只有存在着
B
第
C
直接找以每个点向左向右能扩展到的最远区间。
D
总和永远不变,合法状况为
注意到每次操作相当于交换相邻两项前缀和,则合法答案数等价于逆序对数。
E
对每个节点维护用堆子树内可能胜利的最大编号,每次比较当前点和另一个子树相同层节点集合,然后启发式合并即可。
2026.11.23
P15567
9.先给每个位置塞一个球后插板法,
10.划分数
递推式:
答案即为
11.
12.先在每个盒子中都放一个球,然后转成问题
dif:不知道。
2026.11.24
P5748
题目里相当于求一个:
发现这个东西至少是
由于我不想用多项式科技,于是我尝试把它优化到 但是失败了。
查看题解,发现了一个很厉害的
::::info[code]
#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 mod=998244353;
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 tot,n;
int fac[N],ifac[N],prime[N],S[N];
bitset<N> vis;
inline int qpow(int x,int y){
int res=1;
while(y){
if(y&1) res=1ll*res*x%mod;
x=1ll*x*x%mod,y>>=1;
}
return res%mod;
}
inline void init(){
fac[0]=ifac[0]=1;
for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
ifac[N-1]=qpow(fac[N-1],mod-2);
for(int i=N-2;i>=1;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
for(int i=2;i<N;i++){
if(!vis[i]) prime[++tot]=i;
for(int j=1;j<=tot&&1ll*i*prime[j]<N;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
bool ENDM;
signed main(){
init();
int T;T=read();
while(T--){
n=read();
S[0]=0,S[1]=1;
for(int i=2;i<=n;i++){
if(!vis[i]) S[i]=qpow(i,n);
for(int j=1;j<=tot&&prime[j]<=i&&1ll*i*prime[j]<=n;j++){
S[i*prime[j]]=1ll*S[i]*S[prime[j]]%mod;
if(i%prime[j]==0) break;
}
}
int ans=0,sum=0;
for(int i=n;i>=0;i--){
int X=((n-i)&1?-1:1);
sum=(sum+1ll*X*ifac[n-i]%mod+mod)%mod;
ans=(ans+1ll*sum%mod*S[i]%mod*ifac[i]%mod+mod)%mod;
}
output((ans+mod)%mod);
}
CK_TM;
return 0;
}
::::
dif:5.75/11
P8118
一道关联性极其强需要大眼观察的智力题。
我们发现这题和 P2893 超级像,唯一的区别就是有了这个
考虑这么处理:我们直接令
考虑上面那个题(仅单调不降)的做法怎么做:我们有一个
从左到右,把当前位置的数放进大根堆,然后比较这个数和堆顶的大小:
-
若不小于堆顶,则不管。
-
若比堆顶小,就把堆顶拿出来变成这个数,然后答案增加堆顶与这个数的差,再塞入这个数。
乍一眼这个东西是神经病,于是我们尝试证明:
以下内容来自 deepseek:
::::info[prof]
证明
记原数组为
令
则
也就是说,对
因此原问题完全等价于:把序列
下面证明大根堆贪心的正确性。
引理: 对任意序列
- 把
X_i 放入H ; - 若
X_i< H_{\max} ,则令cost\leftarrow cost+(H_{\max}-X_i), 弹出堆顶,再把
X_i 放入堆中。
处理完前
的最小值。
证明:
设
即
由于绝对值函数是凸函数,且“前缀非降”约束是线性约束,所以
初始时没有元素,
考虑从
- 若
X_i\ge H_{\max} ,说明新的X_i 不会迫使前面已经确定的拐点下降,直接把它加入堆中即可,不产生额外代价。 - 若
X_i< H_{\max} ,说明当前最大的拐点H_{\max} 太高了。为了让序列保持非降,同时使总代价最小,应当把最高的这个拐点压到X_i 。这样做产生的代价正好是H_{\max}-X_i. 并且由于选择的是最大拐点,压低它带来的代价最小,所以这一步贪心最优。于是弹出
H_{\max} ,再把X_i 放回堆中。
归纳可知,处理完前
回到本题。代码中先把
然后对变换后的序列执行上述堆贪心。每次产生的增量
累加到
for(int i=1;i<=n;i++) ans[i]+=ans[i-1];
因此
- 当
T=0 时,输出每个前缀的答案ans_i ; - 当
T=1 时,输出整个序列的答案ans_n 。
所以算法正确。复杂度为
| 这样证明部分就完整了:先说明 |
|---|
::::info[code]
#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,k,T;
int a[N],ans[N];
pq<int> q;
bool ENDM;
signed main(){
n=read(),k=read();
for(int i=1;i<=n;i++) a[i]=read()-i*k;
T=read();
for(int i=1;i<=n;i++){
q.push(a[i]);
if(a[i]<q.top()){
ans[i]+=q.top()-a[i];
q.pop();q.push(a[i]);
}
}
for(int i=1;i<=n;i++) ans[i]+=ans[i-1];
if(!T) for(int i=1;i<=n;i++) output(ans[i]);
else write(ans[n]);
CK_TM;
return 0;
}
::::
dif:7.5/11
P6715
这 dp 好强,目测不输于这题。
发现判定性问题是可做的,但直接构造方案二分答案来判定的话,由于内部人的分布会影响决策,因此这样思考是没有前途的。
注意到一个非常重要的转化:我们从左向右考虑问题,如果一个人能从
设
转移有:
::::info[code]
#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=1e3+5;
constexpr int M=1e4+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,m,k,ans;
int a[N],b[N],dp[N][M<<2];
bool ENDM;
signed main(){
n=read(),k=read();m=k;
for(int i=1;i<n;i++){
a[i]=read(),b[i]=read();
m=max(m,a[i]+b[i]);
}
for(int i=0;i<k;i++) dp[1][i]=i;
for(int i=1;i<n;i++){
int mx=-ll_inf;
for(int j=0;j<m;j++){
if(j>=a[i]+b[i]) dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
else if(j>=a[i]) dp[i+1][j-a[i]]=max(dp[i+1][j-a[i]],dp[i][j]);
else mx=max(mx,dp[i][j]),dp[i+1][j+b[i]]=max(dp[i+1][j+b[i]],dp[i][j]+b[i]);
}
for(int j=0;j<b[i];j++) dp[i+1][j]=max(dp[i+1][j],mx+j);
}
for(int i=0;i<m;i++) ans=max(ans,dp[n][i]);
write(ans);
CK_TM;
return 0;
}
::::
dif:7.25/11
P4137
自从会用 bitset 以后,碰见有 mex 的 ds 题我就没有不是一遍 AC 的,轮椅真强。
dif:3.5/11
2026.11.25
ZR Day 20
我有失智症。
又是传奇挂分大赛。
和绿红鱼加起来挂了将近 250pts,梦回去年在 ZR 和火魔以及宋叫人加起来挂 800pts 的时光。
发现自己的细节处理有点粗,很多东西要么想多要么想少,导致流失了很多时间。
希望 noip 能把挂的分加回来。
::::info[但是]
| 火魔真的强 |
|---|
T1
赛时失智。
这个东西可以先做一遍前缀和,然后操作的含义就进行了修改:
1.全局
2/3/4.选择一个位置
我们无非要让操作
直接取
::::info[code]
#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 n;
int a[N],b[N],c[N];
bool ENDM;
signed main(){
int T,Case;T=read(),Case=read();
while(T--){
n=read();
for(int i=1;i<=n;i++) a[i]=read()+a[i-1];
for(int i=1;i<=n;i++) b[i]=read()+b[i-1];
for(int i=1;i<=n;i++) c[i]=a[i]-b[i];
c[n+1]=0;int mid=n/2+1,ori=c[n];
nth_element(c+1,c+mid,c+n+1+1);
int ans=0,ave=max(0ll,max(c[mid],ori));
for(int i=1;i<=n+1;i++) ans+=abs(ave-c[i]);
output(ans);
}
CK_TM;
return 0;
}
::::
dif:4/11
T2
这个连边方式真的是创造性的。
赛场上想出了不可能到后代再坐地铁回到祖先的性质,但是建图完全是智力缺陷的患者都干不出的行为,用了 smt+odt 优化建图,直接被 ZR 评测机把 DSC 甩得到处都是。
事实证明我的图论真是一坨希望 noip 不要考
不过这个
又因为 fread 开小调了一会,我联赛用它我直接吃
::::info[code]
#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=2e6+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,m,a,b,tot;
int dep[N],dis[N],head[N];
bitset<N> vis;
vector<signed> g[N];
pair<signed,signed> r[N];
struct edge{
signed to,next;
int val;
}e[N*6];
struct node{
int idx,w;
inline friend bool operator < (node A,node B){
return A.w>B.w;
}
};pq<node> q;
void dfs(int u,int f){
dep[u]=dep[f]+1;
for(auto v:g[u]){
if(v==f) continue;
dfs(v,u);
}
}
inline void addedge(int u,int v,int w){
tot++;
e[tot].to=v;
e[tot].val=w;
e[tot].next=head[u];
head[u]=tot;
}
inline void dijkstra(int s){
vis.reset();
for(int i=1;i<=n;i++) dis[i]=ll_inf;
while(!q.empty()) q.pop();
dis[s]=0;q.push({s,dis[s]});
while(!q.empty()){
int u=q.top().idx;q.pop();
if(vis[u]) continue;
vis.set(u);
for(int i=head[u];i;i=e[i].next){
int v=e[i].to,w=e[i].val;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push({v,dis[v]});
}
}
}
for(int i=1;i<=n;i++) spaceput(dis[i]);
putchar('\n');
}
inline void CCC(){
tot=0;
for(int i=0;i<=n+1;i++){
dep[i]=head[i]=0;r[i]=mkpr(0,0);
g[i].clear();g[i].shrink_to_fit();
}
}
bool ENDM;
signed main(){
int T,Case;T=read(),Case=read();
while(T--){
n=read(),m=read(),a=read(),b=read();
CCC();
for(int i=1;i<n;i++){
int u,v;u=read(),v=read();
g[u].pb(v),g[v].pb(u);
r[i]=mkpr(u,v);
}
dfs(1,0);
for(int i=1;i<n;i++){
int x=r[i].first,y=r[i].second;
if(dep[x]>dep[y]) swap(x,y);
addedge(x,y,a),addedge(y,x,0);
}
for(int i=1;i<=m;i++){
int u,v;u=read(),v=read();
addedge(u,v,2*b);
}
dijkstra(1);
}
CK_TM;
return 0;
}
::::
dif:5.75/11
T3
我不会 NTT,别搞。
有空写个
不对这题根本不是题。
更严重的问题来了:我声称我不会二项式反演。
发了个讨论版,得到了一些解答。
大概是将恰好转成至少之后作容斥并合并等价类。
然后我不会……咋办
可能明天练计数的时候订正吧。
T4
好题。
首先证明一个性质:如果某个区间内有
::::info[prof] 比如有一个序列:
其中
当前要取这一段:
发现在长度为
然后把这个区间删掉,两端合并后就变成了一个
因此一定可行。
::::
下设
先将
维护
然后我们可以设
贴个
::::info[
#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=2e6+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,a,b,L;
int mx[N],mn[N],dp[N];
//前缀最大值/最小值
//dp[i]表示前i个位置最多能消几次
char c[N];
bool ENDM;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T,Case;cin>>T>>Case;
while(T--){
cin>>n>>a>>b;L=a+b;
for(int i=1;i<=n;i++) dp[i]=mx[i]=mn[i]=0;
for(int i=1;i<=n;i++){
cin>>c[i];
mx[i]=mx[i-1],mn[i]=mn[i-1];
if(c[i]!='?'){
if(c[i]=='0') mx[i]+=b,mn[i]+=b;
else mx[i]-=a,mn[i]-=a;
}
else mx[i]+=b,mn[i]-=a;
}
for(int i=L;i<=n;i++){
dp[i]=dp[i-1];
int k=i/L;
for(int j=1;j<=k;j++){
int p=i-j*L+1;
if(mn[i]-mn[p-1]<=0&&mx[i]-mx[p-1]>=0) dp[i]=max(dp[i],dp[p-1]+j);
}
}
output(n-L*dp[n]);
}
CK_TM;
return 0;
}
::::
思考这个东西怎样优化:
我们发现 dp 可以转移的情况,当且仅当
然后问题就变成了:维护一个 ds,其可以插入,删除区间,并查询区间的包含关系。
set(odt),动态开点值域线段树,平衡树啥的都能写,是单老哥的。
当然如果你没有维护区间而是暴力维护等价类
由于线段数量是
贴下 因为姜老师已经写了线段树写法,大家快去%%%。
::::info[
#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=2e6+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,a,b;
int mx[N],mn[N],dp[N];
//前缀最大值/最小值
//dp[i]表示前i个位置最多能消去的长度
char c[N];
set<pii> s[N];
#define IT set<pii>::iterator
inline int cov(int id,int l,int r){
if(id<0) return 0;
IT it=s[id].lower_bound(mkpr(l,-ll_inf));
if(it!=s[id].end()&&it->second<=r) return 1;
return 0;
}
inline void add(int id,int l,int r){
if(id<0) return;
IT it=s[id].lower_bound(mkpr(l,-ll_inf));
if(it!=s[id].end()&&it->second<=r) return;
while(it!=s[id].begin()){
IT pos=prev(it);
if(pos->second<r) break;
s[id].erase(pos);
}
s[id].insert(mkpr(l,r));
}
bool ENDM;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T,Case;cin>>T>>Case;s[0].insert(mkpr(0,0));
while(T--){
cin>>n>>a>>b;
for(int i=1;i<=n;i++) dp[i]=mx[i]=mn[i]=0;
for(int i=1;i<=n;i++){
cin>>c[i];
mx[i]=mx[i-1],mn[i]=mn[i-1];
if(c[i]!='?'){
if(c[i]=='0') mx[i]+=b,mn[i]+=b;
else mx[i]-=a,mn[i]-=a;
}
else mx[i]+=b,mn[i]-=a;
}
for(int i=1;i<=n;i++){
dp[i]=dp[i-1];
if(cov(i-dp[i]-a-b,mn[i],mx[i])) dp[i]+=a+b;
add(i-dp[i],mn[i],mx[i]);
}
output(n-dp[n]);
for(int i=1;i<=n;i++) s[i].clear();
}
CK_TM;
return 0;
}
::::
dif:7.5/11
P3674
我在此宣称我是 lpzx bitset rank 1
bitset 板子题。
维护 Ema 和 Hiro,其中
1.等价于(Ema&(Ema<<x)).any()
2.等价于(Ema&(Hiro>>(V-x))).any()
3.直接暴力枚举因数 check
复杂度
::::info[code]
#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=1e5+5;
constexpr int V=1e5;
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,m,B;
int a[N],ans[N],ct[N];
bitset<N> Ema,Hiro;
struct ask{
int op,l,r,x,id;
inline friend bool operator < (ask U,ask V){
if(U.l/B!=V.l/B) return U.l<V.l;
else if(U.l/B%2==1) return U.r<V.r;
return U.r>V.r;
}
}q[N];
inline void add(int x){
ct[x]++;
if(ct[x]==1) Ema.set(x),Hiro.set(V-x);
}
inline void del(int x){
ct[x]--;
if(!ct[x]) Ema.reset(x),Hiro.reset(V-x);
}
bool ENDM;
signed main(){
n=read(),m=read();B=sqrt(n);
Ema.reset(),Hiro.reset();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++) q[i].op=read(),q[i].l=read(),q[i].r=read(),q[i].x=read(),q[i].id=i;
sort(q+1,q+m+1);
for(int i=1,l=1,r=0;i<=m;i++){
while(l>q[i].l) add(a[--l]);
while(r<q[i].r) add(a[++r]);
while(l<q[i].l) del(a[l++]);
while(r>q[i].r) del(a[r--]);
if(q[i].op==1){
int x=q[i].x;
int flag=(Ema&(Ema<<x)).any();
ans[q[i].id]=flag;
}
else if(q[i].op==2){
int x=q[i].x;
int flag=(Ema&(Hiro>>(V-x))).any();
// if(x%2==0) flag|=Ema[x/2];
ans[q[i].id]=flag;
}
else{
int x=q[i].x,flag=0;
for(int i=1;i<=sqrt(x);i++){
if(x%i!=0) continue;
if(Ema[i]&&Ema[x/i]){
flag=1;break;
}
}
ans[q[i].id]=flag;
}
}
for(int i=1;i<=m;i++){
if(ans[i]) cout<<"hana"<<'\n';
else cout<<"bi"<<'\n';
}
CK_TM;
return 0;
}
::::
dif:4.5
2026.11.26
P5355
和 P3674 差不多,但是加了一个除法操作,难了一倍。
考虑根号分治:
-
当
x \ge \sqrt V 时,可能成为答案的V \times k 和k 的组数小于\sqrt V ,直接做。 -
当
x < \sqrt V 时,对每个x 扫一遍序列,维护最近的位置即可,复杂度同样n \sqrt V 。
视
::::info[code]
#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=1e5+5;
constexpr int V=1e5;
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,m,B;
int a[N],ans[N],ct[N],lst[N],res[N];
bitset<N> Ema,Hiro,Yuki;
vi exe,eva[N];
struct ask{
int op,l,r,x,id;
inline friend bool operator < (ask U,ask V){
if(U.l/B!=V.l/B) return U.l<V.l;
else if(U.l/B%2==1) return U.r<V.r;
return U.r>V.r;
}
}q[N];
inline void add(int x){
ct[x]++;
if(ct[x]==1) Ema.set(x),Hiro.set(V-x);
}
inline void del(int x){
ct[x]--;
if(!ct[x]) Ema.reset(x),Hiro.reset(V-x);
}
bool ENDM;
signed main(){
n=read(),m=read();B=sqrt(n);
Ema.reset(),Hiro.reset();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++) q[i].op=read(),q[i].l=read(),q[i].r=read(),q[i].x=read(),q[i].id=i;
sort(q+1,q+m+1);
for(int i=1,l=1,r=0;i<=m;i++){
while(l>q[i].l) add(a[--l]);
while(r<q[i].r) add(a[++r]);
while(l<q[i].l) del(a[l++]);
while(r>q[i].r) del(a[r--]);
if(q[i].op==1){
int x=q[i].x;
int flag=(Ema&(Ema<<x)).any();
ans[q[i].id]=flag;
}
else if(q[i].op==2){
int x=q[i].x;
int flag=(Ema&(Hiro>>(V-x))).any();
ans[q[i].id]=flag;
}
else if(q[i].op==3){
int x=q[i].x,flag=0;
for(int i=1;i<=sqrt(x);i++){
if(x%i!=0) continue;
if(Ema[i]&&Ema[x/i]){
flag=1;break;
}
}
ans[q[i].id]=flag;
}
else{
int x=q[i].x;
if(x>=B){
int flag=0;
for(int i=1;i*x<=V;i++){
if(Ema[i]&&Ema[i*x]){
flag=1;break;
}
}
ans[q[i].id]=flag;
}
else{//根号分治
if(!x){
ans[q[i].id]=0;continue;
}
eva[x].pb(i);
if(!Yuki[x]) Yuki.set(x),exe.pb(x);
}
}
}
for(auto v:exe){
for(int i=1;i<=V;i++) lst[i]=res[i]=-1;
int mx=-1;
for(int i=1;i<=n;i++){
lst[a[i]]=i;
if(a[i]*v<=V) mx=max(mx,lst[a[i]*v]);
if(a[i]%v==0) mx=max(mx,lst[a[i]/v]);
res[i]=mx;
}
for(auto i:eva[v]) ans[q[i].id]=(q[i].l<=res[q[i].r]);
}
for(int i=1;i<=m;i++){
if(ans[i]) cout<<"yuno"<<'\n';
else cout<<"yumi"<<'\n';
}
CK_TM;
return 0;
}
::::
dif:5/11
P14015
我这辈子都忘不了这个 trick 了。
当要对 01 String 进行相邻同项操作时,可以考虑对奇(偶)数位取反,转化为相邻异项操作。
然后小小分讨,懒得打字了贴个结论:
dif:5.5/11
P17777
诈骗神题。
依旧期望的线性性发力:我们无需关心选择的顺序,只需要将每个人分别考虑后相加即可。
由于
dif:4.75/11
P6163
好妙的贪心,太难了。
先将原来的矩形拆成一半,这样输出
对于
考虑每个
我们想要令绝对值(其实没必要)最小,则将左端点降序排序,右端点升序排序,贪心匹配即可。
::::info[code]
#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=3e5+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,ans;
int l[N],r[N];
inline int cmp(int Ema,int Hiro){
return Ema>Hiro;
}
bool ENDM;
signed main(){
n=read();
for(int i=1;i<=n;i++) l[i]=read(),r[i]=read();
sort(l+1,l+n+1,cmp);sort(r+1,r+n+1);
for(int i=1;i<=n/2&&l[i]>r[i];i++) ans+=(n-2*i+1)*(l[i]-r[i]);
write(2*ans);
CK_TM;
return 0;
}
::::
dif:5.75/11
P13364
这道题告诉我们两件事情:
1.打比赛有做法要敢去写
2.证明时思路要严谨
这个东西不独立,所以任何说所谓“长度为
直接搬 Ri 的题解:
代码红,思维至少紫,建议评灰。
CF620E
写到【模板】树链剖分了。
可以用状压线段树或 ODT 直接过,注意 ODT 要加上剪枝才能过。