2023牛客暑期多校组队赛第九场补题

目录

D:Non-Puzzle: Error Permutation

I:Non-Puzzle: Segment Pair


B. Semi-B. Semi-PuzzB. Semi-Puzzle: Brain Stormle: Brain StormPuzzle: Brain Storm
BB

B:Semi-Puzzle: Brain Storm

. Semi-Puzzle: Brain Storm

题意 找到 a u u mod m。留坑

D:Non-Puzzle: Error Permutation

 题意给定长度为 n 的排列,计算有多少个子区间满足子区间第 k 小的数不在 子区间第 k 位。n 5000

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x)  cout << "*** " << #x" = " << x << endl;
const int N=5005;
int a[N];
int b[N][N],pos[N];
void solve() {
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)cin>>a[i];
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++)b[i][j]=0;
		pos[0]=i;
		int cnt=0;
		for(int j=i+1; j<=n; j++) {
			if(a[j]<a[i]) {
				cnt++;
				pos[cnt]=j;
			}
		}
		while(cnt<=n)cnt++,pos[cnt]=n+1;
		int pre=0;
		for(int j=i; j>=1; j--) {
			int k=i-j+1;
			if(a[j]<a[i])pre++;
			if(k-pre-1<0)continue;
			int p=k-pre-1;
			b[j][pos[p]]++;
			b[j][pos[p+1]]--;
		}

	}

	int ans=0;
	for(int i=1; i<=n; i++) {
		int res=0;
		for(int j=i; j<=n; j++) {
//			cout<<i<<" "<<j<<endl;
//			debug(b[i][j]);
			res+=b[i][j];
			if(res==0)ans++;
		}
	}
	cout<<ans<<'\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)solve();
	return 0;
}

I:Non-Puzzle: Segment Pair

给定 n 个区间对 \left [ L_{i},R_{i} \right ], \left [ L'_{i},R'_{i} \right ],从每对区间中选择一个,使得它们至少包含一个公共点,问方
案数。
我们以
3
1 3 3 5
1 4 4 5
1 5 5 5
(比赛的时候自己造的样例)为例

 

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int N=5e5+100;
const int mod=1e9+7;
ll ksm(ll a,ll n) {
	ll ans=1;
	while(n) {
		if(n&1)ans=ans*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans;
}
vector<int>in[N],out[N];
int cntt[N],ans;
void solve() {
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) {
		int l1,r1,l2,r2;
		cin>>l1>>r1>>l2>>r2;
		in[l1].push_back({i});
		in[l2].push_back({i});
		out[r1+1].push_back({i});//注意右端点+1
		out[r2+1].push_back({i});
	}
	int cnt=0;//当前有效的 区间数量
	int sum_in=0;//当前可以选择的 区间 对 总数
	for(int i=1; i<=N-10; i++) {
		for(auto x:out[i]) {//要先让无效区间对出去,不然会对统计当前有效方案数产生干扰
			cntt[x]--;
			if(cntt[x]==0)cnt--;
			sum_in--;
		}
		for(auto x:in[i]) {
			cntt[x]++;
			if(cntt[x]==1)cnt++;
			sum_in++;
			if(cnt==n) {
				int cnt_2=sum_in-(n-1)-cntt[x];
				ans=(ans+ksm(2,cnt_2))%mod;
			}
		}
	}
	cout<<ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--)solve();
	return 0;
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值