首页 > 其他分享 >CSP2024 前集训:多校A层冲刺NOIP2024模拟赛03

CSP2024 前集训:多校A层冲刺NOIP2024模拟赛03

时间:2024-10-07 19:21:48浏览次数:1  
标签:03 unlocked int void 多校 Tp CSP2024 read inline

前言

image

T1 没想到正难则反,脑瘫了没敢用 bitset(复杂度擦边但卡常能过),T2 空间开大了挂了 \(100pts\),\(T3\) 是原。

T1 五彩斑斓

  • 部分分 \(20pts\):\(O(n^4)\) 暴力。

  • 部分分 \(20+?pts\):进行一些优化,极限数据下仍是 \(O(n^4)\)。

  • 部分分 \(60\sim 100pts\):bitset 优化一下,\(O(\frac{n^4}{w})\)。

  • 正解:

    正难则反,求四个角都相同的个数再用总数减。

    枚举行 \(i\) 和行 \(j\),若 \(a_{i,k}=a_{j,k}\) 则答案加上 \(\sum\limits_{h=1}^{k}[a_{i,k}=a_{j,k}]\),可以开桶处理,清空的时候循环 \(k\) 进行清空即可。

    点击查看代码
    #include<bits/stdc++.h>
    #define ll long long 
    #define endl '\n'
    #define sort stable_sort
    using namespace std;
    const int N=410,M=1e6+10;
    template<typename Tp> inline void read(Tp&x)
    {
        x=0;register bool z=true;
        register char c=getchar_unlocked();
        for(;!isdigit(c);c=getchar_unlocked()) if(c=='-') z=0;
        for(;isdigit(c);c=getchar_unlocked()) x=(x<<1)+(x<<3)+(c^48);
        x=(z?x:~x+1);
    }
    template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);}
    template<typename Tp> inline void wt(Tp x){if(x>9)wt(x/10);putchar_unlocked((x%10)+'0');}
    template<typename Tp> inline void write(Tp x){if(x<0)putchar_unlocked('-'),x=~x+1;wt(x);}
    template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar_unlocked(' ');write(y...);}
    int n,m,a[N][N],cnt[M]; ll ans;
    signed main()
    {
        freopen("colorful.in","r",stdin),freopen("colorful.out","w",stdout);
        read(n,m);
        for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) read(a[i][j]);
        for(int i=1;i<=n;i++) for(int j=i;j<=n;j++)
        {
            for(int k=1;k<=m;k++) if(a[i][k]==a[j][k]) ans+=(++cnt[a[i][k]]);
            for(int k=1;k<=m;k++) if(a[i][k]==a[j][k]) cnt[a[i][k]]=0;
        }
        write(1ll*n*(n+1)*1ll*m*(m+1)/4-ans);
    }
    

T2 错峰旅行

  • 部分分 \(20pts\):\(O(t-s)\) 暴力。

  • 部分分 \(80pts\):发现只关心每个时间点有多少个城市可以去,发现 \([s,t]\) 可以划分成至多 \(2m+1\) 个区间,每个区间内的情况是完全一致的,所以动态开点线段树维护即可,复杂度 \(O(m\log(v))\),\(v=10^9\),但是空间开不下,开大了就会爆零。

  • 正解:

    发现离散化一下就可以直接差分做了,复杂度 \(O(m\log(m))\),瓶颈在于离散化。

    点击查看代码
    #include<bits/stdc++.h>
    #define ll long long 
    #define endl '\n'
    #define sort stable_sort
    using namespace std;
    const int N=2e6+10,P=1e9+7;
    template<typename Tp> inline void read(Tp&x)
    {
        x=0;register bool z=true;
        register char c=getchar_unlocked();
        for(;!isdigit(c);c=getchar_unlocked()) if(c=='-') z=0;
        for(;isdigit(c);c=getchar_unlocked()) x=(x<<1)+(x<<3)+(c^48);
        x=(z?x:~x+1);
    }
    template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);}
    template<typename Tp> inline void wt(Tp x){if(x>9)wt(x/10);putchar_unlocked((x%10)+'0');}
    template<typename Tp> inline void write(Tp x){if(x<0)putchar_unlocked('-'),x=~x+1;wt(x);}
    template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar_unlocked(' ');write(y...);}
    int n,m,s,t,tot,ans,a[N],b[N],c[N],l[N],r[N];
    int qpow(int a,int b)
    {int res=1; for(;b;b>>=1,a=1ll*a*a%P) if(b&1) res=1ll*res*a%P; return res;}
    signed main()
    {
        freopen("travel.in","r",stdin),freopen("travel.out","w",stdout);
        read(n,m,s,t),b[++tot]=s,b[++tot]=s+1,b[++tot]=t+1;
        for(int i=1,x;i<=m;i++) read(x,l[i],r[i]),b[++tot]=l[i],b[++tot]=r[i]+1;
        sort(b+1,b+1+tot),tot=unique(b+1,b+1+tot)-(b+1);
        for(int i=1;i<=m;i++)
        {
            c[lower_bound(b+1,b+1+tot,l[i])-b]++;
            c[lower_bound(b+1,b+1+tot,r[i]+1)-b]--;
        }
        for(int i=1;i<=tot;i++) a[i]=a[i-1]+c[i]; ans=n-a[1];
        for(int i=3;i<=tot;i++) ans=1ll*ans*qpow(n-a[i-1],b[i]-b[i-1])%P;
        write(ans);
    }
    

T3 线段树

详见 NOIP2024模拟2

T4 量子隧穿问题

发现是一棵基环树森林,只关心节点 \(n\) 所在的连通块。

对于树上的情况直接处理即可,有定义 \(p_i\) 表示点 \(i\) 有猫的概率,对于边 \((x,y)\),有 \(p_x'=p_x\times p_y,p_y'=p_y+p_x\times(1-p_y)\)。

考虑如何处理环,发现环上编号最小的边的状态存在后效性,遂钦定该条边连接两点的状态,然后按照树上处理,最后乘上这种状态的概率即可。

点击查看代码
#include<bits/stdc++.h>
#define ll long long 
#define endl '\n'
#define sort stable_sort
using namespace std;
const int N=5010,P=1e9+7,inv2=500000004;
template<typename Tp> inline void read(Tp&x)
{
	x=0;register bool z=true;
	register char c=getchar_unlocked();
	for(;!isdigit(c);c=getchar_unlocked()) if(c=='-') z=0;
	for(;isdigit(c);c=getchar_unlocked()) x=(x<<1)+(x<<3)+(c^48);
	x=(z?x:~x+1);
}
template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);}
template<typename Tp> inline void wt(Tp x){if(x>9)wt(x/10);putchar_unlocked((x%10)+'0');}
template<typename Tp> inline void write(Tp x){if(x<0)putchar_unlocked('-'),x=~x+1;wt(x);}
template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar_unlocked(' ');write(y...);}
int T,n,ans,pos,p[N],to[N]; char s[N];
struct dsu
{
	int f[N];
	void init(int n) {for(int i=1;i<=n;i++) f[i]=i;}
	int find(int x) {return x==f[x]?x:f[x]=find(f[x]);}
	bool same(int x,int y) {return find(x)==find(y);}
	bool merge(int x,int y) {return (x=find(x))==(y=find(y))?1:!(f[y]=x);}
}t1,t2;
signed main()
{
	freopen("experiment.in","r",stdin),freopen("experiment.out","w",stdout);
	for(read(T);T;T--)
	{
		read(n),scanf("%s",s+1); ans=0,t1.init(n),t2.init(n); 
		for(int i=1;i<=n;i++) read(to[i]),t1.merge(i,to[i]);
		for(int i=n;i>=1;i--) if(t1.same(i,n)&&t2.merge(i,to[i])) pos=i;
		for(int s1=0;s1<=1;s1++) for(int s2=0;s2<=1;s2++)
		{
			for(int i=1;i<=n;i++) p[i]=s[i]=='C'?1:(s[i]=='?'?inv2:0);
			int q=1; for(int i=1,x,y;i<=n;i++)
			{
				if(i==pos) 
				{
					q=1ll*(s1?p[pos]:1-p[pos]+P)*(s2?p[to[pos]]:1-p[to[pos]]+P)%P;
					if(!q) break; p[i]=s1,p[to[i]]=s2;
				}
				p[i]=1ll*(x=p[i])*(y=p[to[i]])%P,p[to[i]]=(1ll*x*(1-y+P)%P+y)%P;
			}
			(ans+=1ll*q*p[n]%P)%=P;
		}
		for(int i=1;i<=n;i++) if(s[i]=='?') (ans*=2)%=P;
		write(ans),puts("");
	}
}

总结

  • 注意正难则反。
  • 擦边的复杂度也要打,肯定比纯暴力分高。
  • 这个破 OJ 空间开多大算多大,开大直接爆零。
  • 静态可差分问题完全可以不用线段树。

标签:03,unlocked,int,void,多校,Tp,CSP2024,read,inline
From: https://www.cnblogs.com/Charlieljk/p/18450461

相关文章

  • 多校A层冲刺NOIP2024模拟赛03
    多校A层冲刺NOIP2024模拟赛03还有一个半小时结束才来,题基本没打,全口胡。T1五彩斑斓(colorful)直接统计答案难做,考虑统计四个顶点都一样的。知道\(n\)行\(m\)列的矩阵有\(\frac{n\times(n+1)\timesm\times(m+1)}{4}\)个子矩阵,这个想成选择矩阵的边界就可以证明。如何统计四......
  • 多校 A 层冲刺 NOIP2024 模拟赛 03
    多校A层冲刺NOIP2024模拟赛03T1五彩斑斓(colorful)签到题直接暴力枚举是\(O(n^4)\),考虑使用\(bitset\)优化,对每个点开个\(bitset\),预处理它所在一行它及它之前相同颜色的位置,这样就只用枚举另一个点所在列,时间复杂度为\(O(n^3+\frac{n^4}{w})\)。T2错峰旅行(travel)......
  • 网站403forbidden怎么解决
    遇到“403Forbidden”错误通常表示服务器拒绝了请求访问某个资源。解决这个问题可以从以下几个方面入手:1.检查权限设置服务器文件权限:确认服务器上的文件和目录权限是否正确。通常文件权限应为 644,目录权限应为 755。使用命令 chmod 和 chown 调整权限:sudochm......
  • 信息学奥赛复赛复习14-CSP-J2021-03网络连接-字符串处理、数据类型溢出、数据结构Map
    PDF文档公众号回复关键字:202410071P7911[CSP-J2021]网络连接[题目描述]TCP/IP协议是网络通信领域的一项重要协议。今天你的任务,就是尝试利用这个协议,还原一个简化后的网络连接场景。在本问题中,计算机分为两大类:服务机(Server)和客户机(Client)。服务机负责建立连接,客户机......
  • 多校A层冲刺NOIP2024模拟赛02 & csp-s模拟9
    多校A层冲刺NOIP2024模拟赛02四道题因为暑假被拉去当模拟赛暑假集训CSP提高模拟22了,遂直接把赛后代码交了上去,然后就被通知换题了。原\(100+100+100+20\)被在accodersNOI上被卡成了\(100+100+90+10\),更改longlong和int后达到了\(100+100+100+30\)。\(T1\)P318......
  • gym103687D / QOJ3998 The Profiteer
    题意有\(n\)个物品,和一个背包容量上限\(m\)。每个物品有价值\(v_i\)和体积\(a_i\)。你需要选择一段区间\([l,r]\),将这个区间内的体积变为\(b_i\),剩下的不变。然后你对这\(n\)个物品做背包,设背包容量结果为\(f(i)\),需要求出有多少段区间使得\(\dfrac{\sum_{i=1}^mf(......
  • CSP2024-S1游记
    额额,由于对自己水平极度自信,所以没怎么练初赛,只做了两张真题,教练一直叫我做NFLS的模拟题,我一个都没做好吧膜拜巨佬ydy,真的勇诶,直接不做(他把卡涂错了,最后61pts)初赛随便考考都能过吧听说这次CCF不仅把J组分线推上90的高位还泄题了,怎么出的卷啊话说回来,这次又是主场作战,所以在前一......
  • 20241006每日一题洛谷P1031
    对题目第一印象:贪心吧,或者纯模拟第一次贪心,由于左右端堆只能想内一堆移动,遂放弃第一次模拟,开多个数组,(可能还要用递归?),遂放弃于是求助如来佛祖:从逻辑上可以看出,第一堆缺或者多的牌只能移动到第二堆上当第一堆达到期望值时,第一堆便不能再做操作,于是,可以将第二堆作为第一堆来处理......
  • 免费TLS--Let's Encrypt 使用说明
    Let'sEncrypt:这是一个由非营利性组织互联网安全研究小组(ISRG)提供的免费、自动化和开放的证书颁发机构。它为众多网站提供TLS证书,其免费证书的签发/续签可以通过脚本自动化完成。Let'sEncrypt免费证书的有效期通常为90天。官方网站为:https://letsencrypt.org/zh-cn/根据官......
  • 2024牛客多校第二场 - I. Red Playing Cards
    思路与官方题解一样,不过我采用了递归的写法,这样就可以避免排序等操作。另外还要注意递归的时候不能让多个不同的递归函数同时修改一个数组,否则这个数组同时被多个函数使用,会很混乱。我这里把它开成了二维来避免这个问题。代码如下:#include<cstdio>#include<algorithm>usingn......