[codeforces 1284B] New Year and Ascent Sequence 容斥原理+桶排序+前缀和+滚动数组
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址http://codeforces.com/contest/1284/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - New Year and Ascent Sequence | GNU C++11 | Happy New Year! | 46 ms | 4500 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;
}