caioj 1362 NOIP2015普及组 第三题 求和
2017-11-10 23:04
274 查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /** caioj 1362 2015 普及组第三题 */ #include<cstdio> const int N=110000; const int NN=10007; int n,m; struct node{ long long id; long long x; int c; }; node a[N]; long long ans; void qsort1(int l,int r){ int i,j; i=l;j=r; node x=a[(i+j)>>1]; while(i<=j){ while(a[i].c<x.c|| a[i].c==x.c&&a[i].id%2<x.id%2) i++; while(a[j].c>x.c|| a[j].c==x.c&&a[j].id%2>x.id%2) j--; if(i<=j){ node t=a[j]; a[j]=a[i]; a[i]=t; i++;j--; } } if(l<j) qsort1(l,j); if(i<r) qsort1(i,r); } int main(){ freopen("caioj1362.in","r",stdin); // freopen("caioj1362.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%lld",&a[i].x); a[i].id=i; } for(int i=1;i<=n;i++){ scanf("%d",&a[i].c); } qsort1(1,n); a[n+1].c=< 4000 /span>m+1; // for(int i=1;i<=n;i++) printf("%d %d %d\n",a[i].c,a[i].id,a[i].x); // printf("------------------------\n"); ans=0;//l int r=1;int l; int s1,s2,s3; while(r<=n){ l=r; while(a[r].c==a[r+1].c&&a[r].id%2==a[r+1].id%2) r++; //统计l-r的结果 if(r==l){ }else{ s1=s2=s3=0; for(int i=l;i<=r;i++){ s1=(s1+a[i].x)%NN; s2=(s2+a[i].id)%NN; s3=(s3+(r-l-1)*a[i].id*a[i].x)%NN; } // printf("%d %d %d\n",s1,s2,s3); ans=(ans+s1*s2+s3)%NN; } r++; } printf("%lld",ans); } |
相关文章推荐
- 洛谷P2671 NOIP2015普及组第三题 求和
- [NOIP2015普及组]求和
- 洛谷P2671 NOIP2015普及组 T3 求和
- NOIP 2015 T3 普及组 求和 公式分解+线扫
- NOIP2015(普及组)T3 求和
- [普及]NOIP 2015 求和
- noip2015 第三题 求和 (取模运算)
- ◆竞赛题目◆◇NOIP2015普及组◇求和
- 【codevs 5131】[NOIP普及组 2015 T3]求和(递推)
- JZOJ(中山纪中) 2018.02.01【NOIP普及组】模拟赛D组 第三题
- NOIP2015普及组第四题解题报告
- 【2015自招必备】NOIP普及组阅读程序写结果题目汇编(含答案)
- 【NOIP2015普及组T4】推销员-优先队列
- NOIP 2002 普及组 复赛 级数求和
- 【NOIP2015普及组】 推销员(纪中数据-标准)
- code vs 5131 求和 noip2015 (数学乱搞)
- 【codevs 5126】[NOIP2015 普及组T4]推销员(贪心)
- NOIP 2015普及组复赛Day1 T1 == Codevs4510 神奇的幻方
- Noip2012 普及组 第三题 摆花
- 【NOIP模拟题】【数学归纳法】【递推】【容斥原理】【等比数列求和】2016.11.15 第三题 小L的珍珠挂饰 题解