排除所有不符合条件后根据当前位置上下界计算,

由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL __int64
const int N=;
const LL mod=;
int t,n,num,b[N],c[N];
bool flag;
LL ans;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&b[i]);
for(int i=;i<n;i++) scanf("%d",&c[i]);
if(b[]!=c[])
{
puts(""); continue;
}
flag=;
num=ans=;
for(int i=;i<n;i++)
{
if(b[i]!=b[i-]&&c[i]!=c[i-] || b[i-]<b[i] || c[i-]>c[i])//不符合条件
{
flag=; break;
}
else if(c[i]!=c[i-]||b[i]!=b[i-]) num++; //已确定的数字数+1
else
{
ans=(ans*(c[i]-b[i]+-num))%mod;//该位上未确定的数字中的符合条件的个数
num++;//已确定的数字数+1
}
}
if(flag)
{
puts(""); continue;
}
printf("%I64d\n",ans);
}
}
/*
2
5
4 4 1 1 1
4 5 5 5 5
*/

BestCoder 2nd Anniversary 1002 Arrange的更多相关文章

  1. hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...

  2. BestCoder 2nd Anniversary的前两题

    Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Su ...

  3. BestCoder 2nd Anniversary

    A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...

  4. BestCoder 1st Anniversary ($) 1002.Hidden String

    Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ...

  5. BestCoder 2nd Anniversary/HDU 5719 姿势

    Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...

  6. hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...

  7. BestCoder 2nd Anniversary 1001 Oracle

    找到最小的非零数字拆开来相加. 高精度. #include <iostream> #include <cstdio> #include <cstring> #inc ...

  8. BestCoder 2nd Anniversary/HDU 5718 高精度 模拟

    Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...

  9. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

随机推荐

  1. 0124——KVC KVO模式

    1.KVC KVC是Key-Value-Coding的简称,它是一种可以直接通过字符串的名 字(key)来访问类属性(实例变量)的机制.而不是通过调用Setter.Getter方法访问.当使用KVO. ...

  2. dispatch_group_t

    最近在写的模块有这样一个问题,要保证所有block里面的东西全都回来之后再执行某一个 例如我要做完所有的数据库操作再刷新界面,数据库的内容很多,所有用到了group  dispatch_group_t ...

  3. UISwitch 监听响应

    UISwitch *swh = [[UISwitch alloc]initWithFrame:CGRectMake(100,100, 50, 30)];        swh.on = YES;    ...

  4. protobuf 参考资料

    Protocol Buffers 官网下载地址:https://developers.google.com/protocol-buffers/docs/downloads Protocol Buffe ...

  5. 使用Promise规定来处理ajax请求的结果

    ajax()返回结果是成功的,调用done()中的回调函数: 失败则调用fail()中的回调函数; always()的回调函数不管成功是否都会调用: 可以是使用then()函数代替done()和fai ...

  6. js数组小结

    1.js数组使用sort()排序 var a = ["1","12","3","4","0"]; d ...

  7. 【solr基础教程之二】索引

    一.向Solr提交索引的方式 1.使用post.jar进行索引 (1)创建文档xml文件 <add> <doc> <field name="id"&g ...

  8. [C++程序设计]函数的递归调用

    在调用一个函数的过程中又出现直接或间接地调用 该函数本身,称为函数的递归(recursive)调用. 包含递归调用的函数称为递归函数. 在实现递归时,在时间和空间上的开销比较大 求n! #includ ...

  9. Effective Java单元测试TestNG - 就是爱Java

    TestNG是另一种单元测试的framework,与JUnit的类似,这次Mix将使用它来撰写测试程序,大部分所引用的class package都一样,只差在JUnit与TestNG的字样,可以直接用 ...

  10. C和指针c6-1

    #include<stdio.h> #include<stdlib.h> char *find_char(char const *source_str, char const ...