hdu 5139(离线处理+离散化下标)

Formula

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1204    Accepted Submission(s): 415

Problem Description

f(n)=(∏i=1nin−i+1)%1000000007
You are expected to write a program to calculate f(n) when a certain n is given.

Input

Multi test cases (about 100000), every case contains an integer n in a single line.
Please process to the end of file.

[Technical Specification]
1≤n≤10000000

Output

For each n,output f(n) in a single line.

Sample Input

2
100

Sample Output

2
148277692

题解:这题太卡了,只能够将所有的询问保存下来,然后排个序,但是数字太大明显不能够作为下标,开个结构体记录下标,然后离散化下标,最后找到下标依次输出。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <queue>
using namespace std;
typedef long long LL;
const LL mod = 1000000007;
struct Ask
{
    LL v;
    int ori;
} ask[200005];
LL a[200005];
int cmp(Ask a,Ask b){
    return a.v<b.v;
}
int main()
{
    int n,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(int i=1;i<id;i++){
        a[ask[i].ori] = i;
    }
    LL cnt = 1,ans=1;
    for(int i=1; i<id; i++)
    {
        for(int j=ask[i-1].v+1; j<=ask[i].v; j++)
        {
            cnt = cnt*j%mod;
            ans = ans*cnt%mod;
        }
        a[ask[i].ori] = ans;
    }
    for(int i=1;i<id;i++){
        printf("%lld\n",a[i]);
    }
}
时间: 2024-11-11 01:25:14

hdu 5139(离线处理+离散化下标)的相关文章

hdu 5139 (离线处理)

题意: f(n)=(∏i=1nin?i+1)%1000000007 You are expected to write a program to calculate f(n) when a certain n is given. 思路: 写出前几项,就很容易得出递推式.但是因为n的数据范围是1~10000000,而内存给的小 ,所以并不能直接打表(MLE) 采用离线处理--先读完,再一次性输出. 中间采取了一点小技巧,先把所有读入的输入按照n的大小排序,使得处理答案时的时间复杂度为线性的,不然会

hdu 3015 Disharmony Trees (离散化+树状数组)

Disharmony Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 663    Accepted Submission(s): 307 Problem Description One day Sophia finds a very big square. There are n trees in the square. T

HDU 3642 线段树+离散化+扫描线

题意:给你N个长方体的左下角和右上角坐标,问你空间中有多少体积是被大于两个不同的立方体覆盖的.x,y~10^6 z~500 考虑到给的z比较小,所以可以直接枚举z,然后跑二维的扫描线就好. 关于处理被不同的线段覆盖三次的问题,可以维护四个信息,cnt,once,twice,more,然后相互推出结果就好. #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #

hdu 4995(离散化下标+模拟)

Revenge of kNN Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 584    Accepted Submission(s): 136 Problem Description In pattern recognition, the k-Nearest Neighbors algorithm (or k-NN for short

hdu 3333 Turing Tree (树状数组+离线处理+离散化)

Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3981    Accepted Submission(s): 1349 Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems a

HDU 5139 Formula --离线处理

题意就不说了,求公式. 解法: 稍加推导能够得出 : f(n) = n! * f(n-1) , 即其实是求: ∏(n!)  ,盲目地存下来是不行的,这时候看见条件: 数据组数 <= 100000, 那么我们可以离线做,先把他们存下来,然后再从小到大扫一边, 也就是最多10000000次乘法的复杂度.然后离线输出即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <

利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组

题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using namespace std; #define LL long long #define ALL(a) a.begin(), a.end() #define pb push_back #define m

HDU 5249 离线树状数组求第k大+离散化

KPI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1160    Accepted Submission(s): 488 Problem Description 你工作以后, KPI 就是你的全部了. 我开发了一个服务,取得了很大的知名度.数十亿的请求被推到一个大管道后同时服务从管头拉取请求.让我们来定义每个请求都有一个重要值.我的

hdu 5139 Formula (找规律+离线处理)

Formula Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 206    Accepted Submission(s): 83 Problem Description f(n)=(∏i=1nin−i+1)%1000000007You are expected to write a program to calculate f(n) w