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. 巨蟒python全栈开发-第6天 is&==

    1.小数据池 2.id 3.decode和encode 小数据池 #小数据池:不要死磕就行#python为了简化,搞出来的一个东西 ID (1)# id()函数可以帮我们查看一个变量的内存地址# a= ...

  2. mfc中 控件 对话框 添加颜色 背景图片

    1 设置对话框透明 在设置控件颜色中要使用 nCtlColor Contains one of the following values, specifying the type of control ...

  3. mysqld.sock

    sudo  service mysql start https://dev.mysql.com/doc/refman/5.7/en/problems-with-mysql-sock.html B.5. ...

  4. Windows服务的调试

    1.服务为其他程序调用的情况:首先停止服务,在项目中设置断点,重新启动服务,点击项目中工具,附加到进程,运行调用服务的程序,即可进入之前设置的断点,进而进行调试. 2.服务内方法为自动执行的情况:首先 ...

  5. SQL 2005 分页存储过程

    -- ============================================= -- Description:   <高效分页存储过程,适用于Sql2005以上> -- ...

  6. 报错:PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\Anaconda3\\Lib\\site-packages\\pywebhdfs'

    Outline 在本(Windows系统)地往 “PAI”(hdfs)上上传数据时,需要安装pywebhdfs包,然后就报错了: 报错信息: PermissionError: [WinError 5] ...

  7. Django页面重定向

    重定向分为永久性重定向和暂时性重定向,在页面上体现的操作就是浏览器会从一个页面自动跳转到另外一个页面.比如用户访问了一个需要权限的页面,但是该用户当前并没有登录,因此我们应该给他重定向到登录页面. 永 ...

  8. Andrew Ng机器学习编程作业:Support Vector Machines

    作业: machine-learning-ex6 1. 支持向量机(Support Vector Machines) 在这节,我们将使用支持向量机来处理二维数据.通过实验将会帮助我们获得一个直观感受S ...

  9. *.hbm.xml映射文件的元素及属性

    1. 每个持久化对象都需要提供一个以类名命名的映射文件,映射文件需要放在和po类同一目录下. 2. 如下是wefepo的映射文件: <hibernate-mapping> <clas ...

  10. JSP--JSP语法--指令--include(动态包含/静态包含)--九大隐式对象--四大域对象--JSP内置标签--JavaBean的动作元素--MVC三层架构

    一.JSP 原理:JSP其实就是一个servlet. Servlet负责业务逻辑处理,JSP只负责显示.开发中,JSP中不能有一行JAVA代码 二.JSP语法 1.    JSP模板元素:JSP中HT ...