2018 11.2 PION模拟赛
期望:100 + 50 + 30 = 180
实际:0 + 50 + 30 =80
期望:100 实际:0
数值有负数,边界应该设为-0x7f 此处 gg
/* 期望的分:50+ */ #include<cmath> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define MAXN 100010 using namespace std; int n,tot,ans; int f[MAXN]; int num[MAXN],w[MAXN],a[MAXN]; int lchild[MAXN],rchild[MAXN]; int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } void pre(int now){ if(now==0) return ; num[++tot]=now; if(rchild[now]) pre(rchild[now]); if(lchild[now]) pre(lchild[now]); } int main(){ //freopen("lpp.in","r",stdin); freopen("point.in","r",stdin); freopen("point.out","w",stdout); n=read(); for(int i=1;i<=n;i++) w[i]=read(); for(int i=1;i<=n;i++){ lchild[i]=read(); rchild[i]=read(); } pre(1); for(int i=1;i<=n;i++) a[i]=w[num[i]]; memset(f,-0x7f,sizeof(f)); for(int i=1;i<=n;i++){ if(a[i]>f[ans]) f[++ans]=a[i]; else{ int x=lower_bound(f+1,f+1+ans,a[i])-f; f[x]=a[i]; } } printf("%d ",ans); } /* 10 -77 -24 21 6 -4 -69 -1 -19 76 -1 5 2 7 8 0 0 6 9 10 4 0 3 0 0 0 0 0 0 0 0 */
/* 期望:50+; */ #include<queue> #include<cmath> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n; long long ans; int a[100010],b[100010]; int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } void work(int l,int r){ if(l==r) return; int mid=(l+r)/2; work(l,mid); work(mid+1,r); int i=l,j=mid+1; int nb=0; while(i<=mid||j<=r){ if(i>mid) b[++nb]=a[j++]; else if(j>r) b[++nb]=a[i++]; else{ if(a[i]<a[j]) b[++nb]=a[i++]; else{ b[++nb]=a[j++]; ans+=mid-i+1; } } } for(i=l;i<=r;++i) a[i]=b[i-l+1]; } int main(){ //freopen("lpp.in","r",stdin); freopen("a.in","r",stdin); freopen("a.out","w",stdout); n=read(); if(n==1){ int x=read();int y=read(); if(x>y) swap(x,y); printf("%d ",(y-x)*2-1); } else if(n==2){ int x1=read();int y1=read(); int x2=read();int y2=read(); if(x1>y1) swap(x1,y1); if(x2>y2) swap(x2,y2); if(x1==x2&&y1==y2){ printf("0 ");return 0; } if(x1<x2&&y1>y2||x2<x1&&y2>y1){ printf("%d ",(y1-x1)*2-1+(y2-x2)*2-1);return 0;} if(x2>y1||x1>y2){ printf("%d ",(y1-x1)*2-1+(y2-x2)*2-1);return 0;} if(y1==x2||y2==x1){ printf("%d ",(y1-x1)*2-1+(y2-x2)*2-1-1);return 0;} if(x2>x1&&x2<y1){ printf("%d ",(y1-x1)*2-1+(y2-x2)*2-1-1-(y1-x2));return 0;} if(x1>x2&&x1<y2){ printf("%d ",(y1-x1)*2-1+(y2-x2)*2-1-1-(y2-x1));return 0;} } else{ for(int i=1;i<=100000;i++) a[i]=i; for(int i=1;i<=n;i++){ int x=read();int y=read(); swap(a[x],a[y]); } work(1,100000); printf("%d ",ans); } }