hdu 5139 数据的离线处理

时间:2022-08-19 00:31:38

所谓的数据离线处理,就是将所有的输入数据全部读入后,在进行统一的操作,这样当然有好处,比如让你算好多数的阶层,但是输入的每个数是没有顺序的,其实跟可以线性的解决,但是由于没有顺序的输入,这样处理的话复杂度就很高,若将输入的这些数据全部先存起来,再排序,然后按从小到大的顺序处理。

f(n)=(∏i=1nin−i+1)%1000000007

You are expected to write a program to calculate f(n) when a certain n is given.

InputMulti 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
OutputFor each n,output f(n) in a single line.Sample Input

2
100

Sample Output

2
148277692 代码示例:
struct node
{
ll f;
ll ans;
int id;
}pre[eps]; bool cmp1(node a, node b){
return a.f < b.f;
} bool cmp2(node a, node b){
return a.id < b.id;
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll n;
int k = 1; while(~scanf("%lld", &n)){
pre[k].f = n;
pre[k].id = k;
k++;
}
sort(pre+1, pre+k, cmp1);
ll s = 1;
ll aa = 1;
int t = 1;
for(ll i = 1; i <= 10000000; i++){
s *= i;
s %= mod;
aa *= s;
aa %= mod;
while (pre[t].f == i){
pre[t++].ans = (aa%mod);
}
}
sort(pre+1, pre+k, cmp2);
for(int i = 1; i < k; i++){
printf("%lld\n", pre[i].ans);
}
return 0;
}