首先,根据题意可得B数组应是单调不升的,C数组是单调不降的。

可以发现A_1 = B_1 = C_1A​1​​=B​1​​=C​1​​,所以如果B_1 \neq C_1B​1​​≠C​1​​无解。

进一步,我们发现如果B_i < B_{i-1}B​i​​<B​i−1​​,A_i = B_iA​i​​=B​i​​;如果C_i > C_{i-1}C​i​​>C​i−1​​,A_i = C_iA​i​​=C​i​​。但是如果B_i < B_{i-1}B​i​​<B​i−1​​和C_i > C_{i-1}C​i​​>C​i−1​​同时满足,就会产生冲突导致无解。

考虑B_i = B_{i-1}B​i​​=B​i−1​​和C_i = C_{i-1}C​i​​=C​i−1​​同时满足的情况,此时应有A_i \in (B_i,C_i)A​i​​∈(B​i​​,C​i​​)且A_iA​i​​没有在之前使用过。因为(B_i,C_i)(B​i​​,C​i​​)是不断变大的,我们只需维护一下这个区间内有多少值已经被使用过了,用乘法原理统计答案即可。注意到如果某时刻A_iA​i​​没有值可以使用,也会导致无解。

时间复杂度O(Tn)O(Tn)。

Arrange

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 543    Accepted Submission(s): 191

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.

 
Source
 
 
#include<iostream>
#include<stdio.h>
using namespace std;
const int maxx = ;
int b[maxx];
int c[maxx];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
int flag=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&b[i]);
if(i!=){
if(b[i]>b[i-]) flag=;
}
}
long long ans=;
for(int i=;i<n;i++){
scanf("%d",&c[i]);
if(i&&flag){
if(c[i]<c[i-]) flag=;
if(c[i]!=c[i-]&&b[i]!=b[i-]) flag=;
if(c[i]-b[i]<i) flag=;
if(c[i]<=b[i]) flag=;
if(c[i]==c[i-]&&b[i]==b[i-])
ans*=(c[i]-b[i]+-i);
else ans*=;
ans%=;
// cout<<" "<<"i"<<i<<" ans: "<<ans<<endl;
}else{
if(b[i]!=c[i]){
flag=;
}
}
}
if(flag){
printf("%lld\n",ans);
}else{
printf("0\n");
}
}
return ;
}

hdu5719 Arrange的更多相关文章

  1. hdu-5719 Arrange(组合数学)

    题目链接: Arrange Time Limit: 8000/4000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others) ...

  2. 通过Measure & Arrange实现UWP瀑布流布局

    简介 在以XAML为主的控件布局体系中,有用于完成布局的核心步骤,分别是measure和arrange.继承体系中由UIElement类提供Measure和Arrange方法,并由其子类Framewo ...

  3. WPF/Silverlight Layout 系统概述——Arrange(转)

    Arrange过程概述 普通基类属性对Arrange过程的影响 我们知道Measure过程是在确定DesiredSize的大小,以便Arrange过程参考这个DesiredSize,确定给MyPane ...

  4. poj 2441 Arrange the Bulls(状态压缩dp)

    Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...

  5. 重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree

    原文:重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree [源码下载] 重新想象 ...

  6. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  7. dplyr 数据操作 数据排序 (arrange)

    在R中,我们在整理数据时,经常需要对数据排序,以便数据增强数据的可读性. 下面我们来看下dplyr中的,arrange函数 arrange(.data, ...) 跟filter()类似,arrang ...

  8. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  9. numpy的函数使用(一):np.arrange()

    arrange函数用于创建等差数组. 返回一个有起点和终点固定长的list e.g.[1, 2, 3],起点是1,终点是5,步长是1.步长相当于等差数列中的公差. 参数:可以接受1.2.3个参数. 注 ...

随机推荐

  1. Git 学习(一)简介及安装

    Git 简介及安装 Git是目前世界上最先进的分布式版本控制系统(没有之一).它的诞生也颇具传奇,Linux创始人Linus花了两周时间自己用C写了一个分布式版本控制系统,这就是Git!有兴趣的话,可 ...

  2. jenkins平台通过maven方式使用sonar报大量关于html/css/js的错误解决办法

    1.如果项目只关注java的源代码扫描,可以在sonar上把检查html.css.js的插件卸载,让后重启sonar避免不需要检查的内容报错误

  3. mysql重置密码和mysql error 1044(42000)错误

    #mysql错误:(密码不正确,需要重置密码) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...

  4. 快速实现一个生产者-消费者模型demo

    package jesse.test1; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.Blo ...

  5. JMS之——ActiveMQ 高可用与负载均衡集群安装、配置(ZooKeeper + LevelDB + Static discovery)

    一.说明 从 ActiveMQ 5.9 开始, ActiveMQ 的集群实现方式取消了传统的 Master-Slave 方式,增加了基于ZooKeeper + LevelDB 的 Master-Sla ...

  6. dijkstra 两点的最短路径 单源 最短路径

    思路以dist数组 来扩充  路径的访问,不断的刷新dist数组 设置一个顶点的集合s,并不断地扩充这个集合,一个顶点属于集合s当且仅当从源点到该点的路径已求出.开始时s中仅有源点,并且调整非s中点的 ...

  7. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何添加自定义Task,如何让程序的一部分拥有不同的执行周期

    右击Tasks,添加一个新的Task,可以设置这个新的任务的扫描周期,比如100ms   右击PLC的整个的Project,然后Add一个Referenced Task,选中你新建的Task   在P ...

  8. iPhone销售拉动 鸿海精密第一季度利润增长21%

    据美国<华尔街日报>5月15日消息,苹果公司主要代工厂鸿海精密发布,第一季度利润增长21%.主要得益于iPhone手机销量强劲以及生产效率提升. 这家全球最大的电子产品代工商近一半的收入是 ...

  9. C#运行原理——我的柔情你永远不懂

    记得歌手陈琳曾经在1993年发行了第一张专辑<你的柔情我永远不懂>,创造了150万张的销售纪录,里边的主打歌——我的柔情你永远不懂,多年以后才发现是写给C#运行原理的,因为原理总是伤不起~ ...

  10. iOS exit(),abort(),assert()函数区别

    iOS exit(),abort(),assert()函数区别 exit() 退出程序 abort() 停止程序, assert()检查里面的参数如果为nil抛出异常: