Arrange

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Problem Description
Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen in love with Psyche.

This has drawn the fury of his mother, Venus. The goddess then throws before Psyche a great mass of mixed crops.

There are n heaps of crops in total, numbered from 1 to n.

Psyche needs to arrange them in a certain order, assume crops on the i-th position is Ai.

She is given some information about the final order of the crops:

1. the minimum value of A1,A2,...,Ai is Bi.

2. the maximum value of A1,A2,...,Ai is Ci.

She wants to know the number of valid permutations. As this number can be large, output it modulo 998244353.

Note that if there is no valid permutation, the answer is 0.

 
Input
The first line of input contains an integer T (1≤T≤15), which denotes the number of testcases.

For each test case, the first line of input contains single integer n (1≤n≤105).

The second line contains n integers, the i-th integer denotes Bi (1≤Bi≤n).

The third line contains n integers, the i-th integer denotes Ci (1≤Ci≤n).

 
Output
For each testcase, print the number of valid permutations modulo 998244353.
 
Sample Input
2
3
2 1 1
2 2 3
5
5 4 3 2 1
1 2 3 4 5
 
Sample Output
1
0

Hint

In the first example, there is only one valid permutation (2,1,3) .

In the second example, it is obvious that there is no valid permutation.

思路:最小值最大值成递减递增函数;前面取的数肯定在之后的区间内,flag一下;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=1e5+,M=1e7+,inf=1e9+;
const ll mod=;
int a[N];
int b[N];
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&x);
ll ans=;
int flag=;
for(i=;i<x;i++)
scanf("%d",&a[i]);
for(i=;i<x;i++)
scanf("%d",&b[i]);
if(a[]!=b[])
ans=;
for(i=;i<x;i++)
{
if(a[i]!=a[i-]&&b[i]!=b[i-])
ans=;
else if(a[i]>a[i-])
ans=;
else if(b[i]<b[i-])
ans=;
else if(a[i]!=a[i-]||b[i]!=b[i-])
flag++;
else
{
ans*=(b[i]-flag-a[i]+);
flag++;
ans%=mod;
}
}
printf("%I64d\n",ans);
}
return ;
}

hdu 5719 Arrange 贪心的更多相关文章

  1. hdu 5719(Arrange)(冷静分析)

    A数组显示从0到i的最小值B数组显示从0到i的最大值由此可得:A数组是单调不增的(怎么也会不使得最小值变大)B数组是单调不减的.设premin和premax为i位以前的最小值和最大值.可以得出以下几点 ...

  2. HDU 5719 Arrange

    根据条件,某些位置的数字就可以确定了.确定过程中如果有冲突,则无解. 如果B中出现了递增,C中出现了递减,则无解. 对于每一个未确定的a[i],ans需要更新,ans=ans*((c[i]-b[i]+ ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

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

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

  6. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

随机推荐

  1. Scala 中我们长见到=> 解析下

    =>这符号其实是映射转化的意思,个人理解,可能不准确, var increase = (x: Int) => x + 1 increase(10) res0: Int = 11 意思就是你 ...

  2. 你不知道的Javascript(上卷)读书笔记之四 ---- 提升、this

    1. 提升 使用var声明的变量声明和函数的声明(函数表达式不会)会被提升至所在函数作用域顶部 a. 从编译器角度出发 回忆一下, 中关于编译器的内容,引擎会在解释 JavaScript 代码之前首先 ...

  3. 并发测试 java.lang.OutOfMemoryError: GC overhead limit exceeded Xms Xmx 阻塞请求 单节点 请求分发 负载均衡

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:705) at javax.servlet.http.HttpServlet.se ...

  4. python 里面的单下划线与双下划线的区别(私有和保护)

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...

  5. Python菜鸟之路:Django 分页

    Django的分页没有多少需要说的,有一点需要关注,在自定制分页功能的时候,需要通过python代码来生成每一页的a标签链接,这个时候需要关注一点:默认情况下,为了安全考虑,防范XSS攻击,Djang ...

  6. css的常用知识点

    一.css的引入方式 1.行内引入 直接在标签中定义样式 <p style="background-color: red">test</p> 2.嵌入式引入 ...

  7. 线程池ThreadPoolExecutor参数设置

    线程池ThreadPoolExecutor参数设置 JDK1.5中引入了强大的concurrent包,其中最常用的莫过了线程池的实现ThreadPoolExecutor,它给我们带来了极大的方便,但同 ...

  8. Pycharm在创建py文件时,自动添加文件头注释

    依次File -> Settings -> Editor -> File and Code Templates -> Python Script   添加以下代码: # -*- ...

  9. SVG Use(转)

    转自:http://www.zhangxinxu.com/wordpress/2014/07/introduce-svg-sprite-technology/ 未来必热:SVG Sprite技术介绍 ...

  10. PHP基础学习代码案例

    <?php print 'hello world ! '; echo '<br/>'; ?> <?php $number="16"; $number2 ...