[codeforces 1284B] New Year and Ascent Sequence 容斥原理+桶排序+前缀和+滚动数组

[codeforces 1284B] New Year and Ascent Sequence   容斥原理+桶排序+前缀和+滚动数组

总目录详见https://blog.csdn.net/mrcrack/article/details/103564004

在线测评地址http://codeforces.com/contest/1284/problem/B

ProblemLangVerdictTimeMemory
B - New Year and Ascent Sequence GNU C++11Happy New Year!46 ms4500 KB

 //提交,Wrong answer on test 9重新读题,发现(0≤si,j≤106)
//for(i=d;i>=0;i--)c[i]+=c[i+1];//此处错写成for(i=d;i>=1;i--)c[i]+=c[i+1];

#include <stdio.h>
#define LL long long
#define maxn 100010
int a[2],mx[maxn],mn[maxn],tot,d,c[maxn*10];
LL ans;
int max(int a,int b){
	return a>b?a:b;
}
int main(){
	int i,j,l,n,t,k=0,check,first;
	scanf("%d",&n),t=n;
	while(t--){
		check=0;
		scanf("%d%d",&l,&first),k=0,a[0]=first;
		for(i=1;i<l;i++){
			k^=1;
			scanf("%d",&a[k]);
			if(a[k^1]<a[k])check=1;//此处错写成if(a[k^1]<a[k]){check=1;break;}
		}
		if(!check)mx[++tot]=first,mn[tot]=a[k];//此处错写成if(!check)mx[++tot]=a[0],mn[tot]=a[k];
	}
	for(i=1;i<=tot;i++)c[mn[i]]++,d=max(mn[i],d);
	for(i=d;i>=0;i--)c[i]+=c[i+1];//此处错写成for(i=d;i>=1;i--)c[i]+=c[i+1];
	for(i=1;i<=tot;i++)ans+=c[mx[i]];
	printf("%lld\n",(LL)n*n-ans);
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值