Hdu 5139 (Off-line processing + discretized subscript)

Source: Internet
Author: User

Formula

Time limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1204 Accepted Submission (s): 415


Problem DescriptionF(N)=(∏I=1NIn−i+1)%1000000007
You were expected to write a program to calculate f (n) when a certain n was given.

Inputmulti test Cases (about 100000), every case contains an integer n-a single line.
Please process to the end of file.

[Technical specification]
n10000000

Outputfor each n,output f (n) in a.

Sample Input2100

Sample Output2148277692: This problem is too card, can only save all the questions, and then order, but the number is too large obviously can not be used as subscript, open a structure to record the subscript, and then discretized subscript, and finally found the subscript in turn output.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespaceStd;typedefLong LongLL;ConstLL mod =1000000007;structask{LL v; intThe Ori;} ask[200005]; LL a[200005];intCMP (Ask a,ask b) {returna.v<B.V;}intMain () {intN,id=1; ask[0].V = ask[0].ori =0;  while(SCANF ("%d", &n)! =EOF) {ASK[ID].V=N; Ask[id].ori=ID; ID++; } sort (Ask+1, ask+id,cmp);  for(intI=1; i<id;i++) {A[ask[i].ori]=i; } LL CNT=1, ans=1;  for(intI=1; i<id; i++)    {         for(intj=ask[i-1].v+1; j<=ask[i].v; J + +) {CNT= cnt*j%MoD; Ans= ans*cnt%MoD; } A[ask[i].ori]=ans; }     for(intI=1; i<id;i++) {printf ("%lld\n", A[i]); }}

Hdu 5139 (Off-line processing + discretized subscript)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.