目录
D:Non-Puzzle: Error Permutation
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
个区间对 , ,从每对区间中选择一个,使得它们至少包含一个公共点,问方
案数。
我们以
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;
}