2026.11.16
洛谷 NOIP 模拟赛。
T1
需要维护一大坨的线段树,场上想出了正解并花了 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
赛时什么都没打。
发现这个东西是可以二分答案的,我们不妨去二分这个中位数。
直接维护连通块是很困难的,这里给出一个很厉害的定义:
pii dp[N][2];
//dp[i][j]表示以i为根的子树,子树内连通块的奇偶性为j时,当前的权值和以及>=limit的连通块数量差 然后要依次讨论删不删 这条边,以及这么做会对子树造成多大的贡献即可。
其余部分见题解。
dif:5.5/11
T3
赛时没打,赛后补了。
我们发现对于一个下标 ,如果 之前的数都不大于 上的元素,且 之后的数都不小于 上之后的元素,则 位置一定会被所有的最长不下降子序列选到。
先考虑填上 的位置。再用一些 的位置和不满足条件的 的位置组成逆序对。发现剩下 的位置中 是单调不降的,于是任意一个 的位置对应能匹配成逆序对的位置是一个区间。
然后就是求最大的区间并,设 表示考虑前 个元素是区间并和的最大值,再维护 的前缀和,则有:
线段树维护最大的 。
dif:6.5/11
T4
场上打了 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 函数。
不过题还是可以订的:
我们发现可以 来 check 一个分割长度是否可能,然后又可以知道只有 的因数是有用的,因此可以尝试在这上面做文章。
发现这个 很特殊,大胆猜测是一坨质因子的乘积。
然后发现前几个小的质因子的乘积小于 ,发现可以对每个质因子的幂次进行二分,总次数小于 次。
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 的 。
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 有点不好证扔给了翁陆恒让他帮我证。
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:3.5/11
2026.11.18
自由练习,VP 了 ZR Day 8。
ZR3729.看门狗
区间 chkmax 线段树模板,随便写写就切了。
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
这题神了。
没订完。
我草我线段树写错了。
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
,建议退役
T1
赛场上的想法不太自然,既维护了左边第一个 的位置,又维护了右边第一个位置,导致式子没有推完。
看看题解是怎么处理这个东西的:
感觉 *2300 左右吧,有点要脑子。
dif:5.5/11
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,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
唯二像题的题。
注意到本题的核心是定义出这两个东西:
//p[i]=f(p[i-1],i)为从0一路向上挑战的结果
//nxt[i]表示p[i]+1与p[i+1]重合的位置我真的觉得这个 数组和 数组的定义非常巧妙,这样就可以把这道题转化为一个分讨数学题了。
dif:6.5/11
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 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
叉姐的题,吓哭了。
最难的就是这个导出子图的分析,不过这题对于拼好分和观察性质的训练是很好的。
但是题解不像人。
dif:7.25/11
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+6e2+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,m,ans;
int S[10],F[10]={0,2,12,6,24,48,36,12,12,24},a[N],b[N];
bitset<N> vis[N];
inline int C2(int x){
return x*(x-1)/2;
}
inline int C3(int x){
return x*(x-1)*(x-2)/6;
}
bool ENDM;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>Case>>n;
for(int i=1;i<=n;i++){
string s;cin>>s;s=" "+s;
for(int j=1;j<=n;j++){
if(s[j]=='1') S[1]++,vis[i].set(j);
}
}
for(int i=1;i<=n;i++){
int v1=vis[i].count();
S[2]+=C2(v1),S[7]+=C3(v1);
for(int j=1;j<=n;j++){
if(i==j) continue;
int v2=vis[j].count(),v3=(vis[i]&vis[j]).count();
if(vis[i][j]) S[3]+=(v1-1)*(v2-1)-v3,S[4]+=v3,S[6]+=C2(v3),a[i]+=v3,b[i]+=C2(v3);
S[5]+=C2(v3),S[8]+=C2(v3)*(v1-2-vis[i][j]);
}
}
for(int i=1;i<=n;i++) S[9]+=a[i]/2*(a[i]/2-1)/2-b[i];
S[1]/=2,S[3]/=2,S[4]/=6,S[5]/=4,S[6]/=2;
for(int i=1;i<=9;i++) ans+=F[i]*S[i];
write(ans);
CK_TM;
return 0;
}T4
依旧是叉姐的题。
原来的 很难写,但你发现这题正睿上开了 2s,且 。
然后就学习了一个非常暴力的 做法。
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
#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;
using namespace __gnu_pbds;
constexpr int N=2e3+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,T,n,m;
cc_hash_table<int,int> mp;
int a[N],b[N],p[N],q[N],sa[N],sb[N],dp[N][N];
bool ENDM;
signed main(){
Case=read(),T=read();
while(T--){
n=read(),m=read();
mp.clear();
for(int i=1;i<=n;i++){
a[i]=read(),p[i]=read();
sa[i]=mp[a[i]];mp[a[i]]=i;
}
mp.clear();
for(int i=1;i<=m;i++){
b[i]=read(),q[i]=read();
sb[i]=mp[b[i]];mp[b[i]]=i;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
if(a[i]!=b[j]) continue;
int A=i,B=j,l=0,r=0;
while(A){
l+=p[A];
while(B){
r+=q[B];
dp[i][j]=max(dp[i][j],dp[A-1][B-1]+min(l,r));
if(r>l){
r-=q[B];break;
}
B=sb[B];
}
A=sa[A];
}
}
}
output(dp[n][m]);
for(int i=1;i<=n;i++){
sa[i]=sb[i]=0;
for(int j=1;j<=m;j++){
dp[i][j]=0;
}
}
}
CK_TM;
return 0;
}dif:5/11
dif:(8)?




















