首先,根据题意可得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. 在ios程序中自己主动滚动TableView到某行的方法

    比方tableview窗体能够显示 30 行, 我想在填充tableview 100 条数据后 选择第 50行, 能把这一行显示到窗体内, 就像手动拖滚动栏到 第 50行一样,要怎样实现呢? ] an ...

  2. iOS:Reachability网络监听

    iOS利用Reachability确认网络环境3G/WIFI 开发Web等网络应用程序的时候,需要确认网络环境,连接情况等信息.如果没有处理它们,是不会通过Apple的审查的,一般情况下,可以把网络监 ...

  3. iOS:quartz2D绘图(显示绘制在PDF上的图片)

    quart2D既可以用来绘制图像到pdf上,也可以从pdf上读取图像并显示出来.在使用这种方式之前,还有一种方式可以用来读取显示pdf上的图像,即使用UIWebView网页视图控件- (void)lo ...

  4. "com.android.ide.s.ProcessException:Process 'cand 'C:\Program Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2"

    使用Android Studio 出现该问题: "com.android.ide.common.process.ProcessException: org.gradle.process.in ...

  5. vue-resource文档详细解读

    Vue可以构建一个完全不依赖后端服务的应用,同时也可以与服务端进行数据交互来同步界面的动态更新.Vue通过插件的形式实现了基于AJAX,JSPNP等技术的服务端通信. vue-resource是一个通 ...

  6. http网络通信--页面源代码查看

    1.要在andorid中实现网络图片查看,涉及到用户隐私问题,所以要在AndroidManifest.xml中添加访问网络权限 <uses-permission android:name=&qu ...

  7. JAVA简单选择排序算法原理及实现

    简单选择排序:(选出最小值,放在第一位,然后第一位向后推移,如此循环)第一位与后面每一个逐个比较,每次都使最小的置顶,第一位向后推进(即刚选定的第一位是最小值,不再参与比较,比较次数减1) 复杂度: ...

  8. 总结this指向问题

    在全局上下文中,this指向全局. 在函数内部,this的值取决于函数被调用的方式. 当函数简单调用时(函数在全局上下文中),this指向window(严格模式下指向undefined) call 或 ...

  9. Android BaseAdapter和ViewHolder 优化 解决ListView的item抢焦点问题和item错乱问题

    首先赞下hyman大神 曾经仅仅是简单的重写个BaseAdapter,将getView方法保持抽象.而ViewHolder没有抽象过. .. ViewHolder (用了一个集合+泛型管理存取view ...

  10. 算法笔记_069:Floyd算法简单介绍(Java)

    目录 1 问题描述 2 解决方案 2.1 使用Floyd算法得到最短距离示例 2.2 具体编码   1 问题描述 何为Floyd算法? Floyd算法功能:给定一个加权连通图,求取从每一个顶点到其它所 ...