# Codeforces Round #737 (Div. 2)

## A - Ezzat and Two Subsequences

# include <bits/stdc++.h>
# define inf 1e9
# define int long long
using namespace std;
const int N=3e5+10;
int a[N],n;
signed main()
{
int t; scanf("%lld",&t);
while (t--) {
scanf("%lld",&n);
int mx=-inf,sum=0;
for (int i=1;i<=n;i++) scanf("%lld",&a[i]),mx=max(mx,a[i]),sum+=a[i];
double ans=mx+(double)(sum-mx)/(double)(n-1);
printf("%.7lf\n",ans);
}

return 0;
}


## B - Moamen and k-subarrays

• 将数组分成恰好$k$个连续的块。
• 任意排列$k$个块
• $k$个块依次排列构成新数组。

$n$个数离散化，由于$a_i$的互异性，最终有序的数组为$1-n$依次排列。

# include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b[N];
map<int,int>mp;
int main()
{
int t; scanf("%d",&t);
while (t--) {
int n,k; scanf("%d%d",&n,&k);
mp.clear();
for (int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
sort(b+1,b+1+n);
for (int i=1;i<=n;i++) mp[b[i]]=i;
for (int i=1;i<=n;i++) a[i]=mp[a[i]];
int ans=n;
for (int i=1;i<n;i++) if (a[i+1]==a[i]+1) ans--;
puts(k>=ans?"Yes":"No");
}
return 0;
}


## C - Moamen and XOR

$n$个数字构成的数组$a_i$，给出$k$，满足$0 \leq a_i < 2^k$.

• $a_1 \& ... \& a_n = a_1 \oplus ... \oplus a_n$
• $a_1 \& ... \& a_n > a_1 \oplus ... \oplus a_n$

• $a_1 \& ... \& a_n = a_1 \oplus ... \oplus a_n = 1$
• $a_1 \& ... \& a_n = a_1 \oplus ... \oplus a_n = 0$

• $n$为奇数，$a_1 = a_2 = ... = a_n = 1$. （情况数为$0$或者$1$，取决于$n$的奇偶性）
• $a_1 ... a_n$至少存在偶数个$a_j = 1$并且至少存在一个$0$.
• $n$为奇数时情况数为$C_{n}^{0} + C_{n}^{2} + ... C_{n}^{n-1}= 2^{n-1}$
• $n$为偶数时情况数为$C_{n}^{0} + C_{n}^{2} + ... C_{n}^{n} - C_{n}^{n}= 2^{n-1}-1$

• $a_1 \& ... \& a_n = a_1 \oplus ... \oplus a_n$

$n$为奇数时：$(2^{n-1}+1)^k$$n$为偶数时：$(2^{n-1}-1)^k$

• $a_1 \& ... \& a_n > a_1 \oplus ... \oplus a_n$$n$为偶数。

# include <bits/stdc++.h>
# define int long long
using namespace std;
const int mo=1e9+7;
int pow(int x,int n){
int ans=1;
while (n) {
if (n&1) ans=ans*x%mo;
x=x*x%mo;
n>>=1;
}
return ans;
}
signed main() {
int t; scanf("%lld",&t);
while (t--) {
int n,k; scanf("%lld%lld",&n,&k);
int res=pow(2ll,n-1);
if (n&1) res=res+1; else res=res-1;
int ans=pow(res,k);
if (!(n&1)) {
for (int i=1;i<=k;i++) {
ans=(ans+pow(res,i-1)*pow(pow(2ll,n),k-i)%mo)%mo;
}
}
printf("%lld\n",ans);
}
return 0;
}


## D - Ezzat and Grid

$n$$10^9$列的$01$矩阵，初始全为$0$,一些行上添加连续的$1$，要求删除最小的行数，满足：

# include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int Lim = 1e9;
struct node{
int l,r;
};
struct tmp {
int val,id;
};
vector<node>a[N];
struct rec{
int l,r,ls,rs,val,id;
tmp tag;
}tr[N<<2];
int tot,n,m,f[N],g[N];
bool vis[N];
int New(int l,int r) {
++tot;
tr[tot].l=l; tr[tot].r=r;
tr[tot].id=-1;
tr[tot].tag.id=-1;
}
void down(int x) {
if (tr[x].tag.val > tr[tr[x].ls].val) tr[tr[x].ls].val = tr[x].tag.val,tr[tr[x].ls].id = tr[x].tag.id;
if (tr[x].tag.val > tr[tr[x].ls].tag.val) tr[tr[x].ls].tag = tr[x].tag;
if (tr[x].tag.val > tr[tr[x].rs].val) tr[tr[x].rs].val = tr[x].tag.val,tr[tr[x].rs].id = tr[x].tag.id;
if (tr[x].tag.val > tr[tr[x].rs].tag.val) tr[tr[x].rs].tag = tr[x].tag;
tr[x].tag=(tmp){0,0};
}
void update(int x,int opl,int opr,int val,int id) {
if (opl<=tr[x].l&&tr[x].r<=opr) {
if (val > tr[x].val) tr[x].val=val,tr[x].id=id;
if (val > tr[x].tag.val) tr[x].tag=(tmp){val,id};
return ;
}
int mid=(tr[x].l+tr[x].r)/2;
if (!tr[x].ls) tr[x].ls = New(tr[x].l,mid);
if (!tr[x].rs) tr[x].rs = New(mid+1,tr[x].r);
down(x);
if (opl<=mid) update(tr[x].ls,opl,opr,val,id);
if (opr>mid) update(tr[x].rs,opl,opr,val,id);
if (tr[x].val < tr[tr[x].ls].val) tr[x].val = tr[tr[x].ls].val,tr[x].id=tr[tr[x].ls].id;
if (tr[x].val < tr[tr[x].rs].val) tr[x].val = tr[tr[x].rs].val,tr[x].id=tr[tr[x].rs].id;
}
tmp query(int x,int opl,int opr) {
if (!x) return (tmp) {0,0};
if (opl<=tr[x].l&&tr[x].r<=opr) {
return (tmp) {tr[x].val,tr[x].id};
}
int mid=(tr[x].l+tr[x].r)/2;
if (!tr[x].ls) tr[x].ls = New(tr[x].l,mid);
if (!tr[x].rs) tr[x].rs = New(mid+1,tr[x].r);
down(x);
tmp res = (tmp){0,0};
if (opl<=mid) {
tmp t=query(tr[x].ls,opl,opr);
if (t.val > res.val) res = t;
}
if (opr>mid) {
tmp t=query(tr[x].rs,opl,opr);
if (t.val > res.val) res=t;
}
return res;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++) {
int id,l,r; scanf("%d%d%d",&id,&l,&r);
a[id].push_back((node){l,r});
}
tot=1;
tr[1].id=-1; tr[1].val=0;
tr[1].l=1; tr[1].r=Lim;
for (int i=1;i<=n;i++) {
for (int j=0;j<a[i].size();j++) {
int l=a[i][j].l,r=a[i][j].r;
tmp w = query(1,l,r);
if (w.val+1>f[i]) {
f[i]=w.val+1; g[i]=w.id;
}
}
for (int j=0;j<a[i].size();j++) {
int l=a[i][j].l,r=a[i][j].r;
update(1,l,r,f[i],i);
}
}
int ans = 0 , ii = -1;
for (int i=1;i<=n;i++) if (f[i]>ans) {
ans=f[i] , ii = i;
}
printf("%d\n",n-ans);
vis[ii]=1;
while (true) {
ii = g[ii];
if (ii <= 0) break;
vis[ii]=1;
}
for (int i=1;i<=n;i++) if (!vis[i]) printf("%d ",i);
puts("");
return 0;
}
// Runtime Error on Test 15


# include <bits/stdc++.h>
using namespace std;
const int N=3e5+10;
const int Lim = 1e9;
struct node{
int l,r;
};
struct tmp {
int val,id;
};
vector<node>a[N];
struct rec{
int val,id;
tmp tag;
}tr[N<<3];
int tot,n,m,f[N],g[N];
bool vis[N];
void down(int x) {
if (tr[x].tag.val > tr[2*x].val) tr[2*x].val = tr[x].tag.val,tr[2*x].id = tr[x].tag.id;
if (tr[x].tag.val > tr[2*x].tag.val) tr[2*x].tag = tr[x].tag;
if (tr[x].tag.val > tr[2*x+1].val) tr[2*x+1].val = tr[x].tag.val,tr[2*x+1].id = tr[x].tag.id;
if (tr[x].tag.val > tr[2*x+1].tag.val) tr[2*x+1].tag = tr[x].tag;
tr[x].tag=(tmp){0,0};
}
void update(int x,int l,int r,int opl,int opr,int val,int id) {
if (opl<=l&&r<=opr) {
if (val > tr[x].val) tr[x].val=val,tr[x].id=id;
if (val > tr[x].tag.val) tr[x].tag=(tmp){val,id};
return ;
}
int mid=(l+r)/2;
down(x);
if (opl<=mid) update(2*x,l,mid,opl,opr,val,id);
if (opr>mid) update(2*x+1,mid+1,r,opl,opr,val,id);
if (tr[x].val < tr[2*x].val) tr[x].val = tr[2*x].val,tr[x].id=tr[2*x].id;
if (tr[x].val < tr[2*x+1].val) tr[x].val = tr[2*x+1].val,tr[x].id=tr[2*x+1].id;
}
tmp query(int x,int l,int r,int opl,int opr) {
if (!x) return (tmp) {0,0};
if (opl<=l&&r<=opr) {
return (tmp) {tr[x].val,tr[x].id};
}
int mid=(l+r)/2;
down(x);
tmp res = (tmp){0,0};
if (opl<=mid) {
tmp t=query(2*x,l,mid,opl,opr);
if (t.val > res.val) res = t;
}
if (opr>mid) {
tmp t=query(2*x+1,mid+1,r,opl,opr);
if (t.val > res.val) res=t;
}
return res;
}
int tt[2*N],T;
int getli(int x) {
return lower_bound(tt+1,tt+1+T,x)-tt;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++) {
int id,l,r; scanf("%d%d%d",&id,&l,&r);
tt[++tt[0]]=l; tt[++tt[0]]=r;
a[id].push_back((node){l,r});
}
sort(tt+1,tt+1+tt[0]);
T=unique(tt+1,tt+1+tt[0])-tt-1;
int mx=0;
for (int i=1;i<=n;i++)
for (int j=0;j<a[i].size();j++) {
a[i][j].l=getli(a[i][j].l);
a[i][j].r=getli(a[i][j].r);
mx = max(mx,a[i][j].l);
mx = max(mx,a[i][j].r);
}
tot=1;
for (int i=1;i<=n;i++) {
for (int j=0;j<a[i].size();j++) {
int l=a[i][j].l,r=a[i][j].r;
tmp w = query(1,1,mx,l,r);
if (w.val+1>f[i]) {
f[i]=w.val+1; g[i]=w.id;
}
}
for (int j=0;j<a[i].size();j++) {
int l=a[i][j].l,r=a[i][j].r;
update(1,1,mx,l,r,f[i],i);
}
}
int ans = 0 , ii = -1;
for (int i=1;i<=n;i++) if (f[i]>ans) {
ans=f[i] , ii = i;
}
printf("%d\n",n-ans);
vis[ii]=1;
while (true) {
ii = g[ii];
if (ii <= 0) break;
vis[ii]=1;
}
for (int i=1;i<=n;i++) if (!vis[i]) printf("%d ",i);
puts("");
return 0;
}

posted @ 2021-08-11 00:14  Maystern  阅读(80)  评论(0编辑  收藏  举报