hdu 5719 Arrange

 1 /*******************************************************
 2 题目:    Arrange(hdu 5719)
 3 链接:    http://acm.hdu.edu.cn/showproblem.php?pid=5719
 4 解法:    可以发现 A1=B1=C1,如果B1不等于C1无解。
 5           如果Bi<Bi-1,那么Ai=Bi;如果Ci>Ci-1,那
 6           么Ai=Ci;如果Bi=Bi-1 && Ci=Ci-1那么 Bi<=Ai<=Ci,
 7           并且Ai前面没使用过。其它情款无解。
 8 
 9 ********************************************************/
10 #include<iostream>
11 #include<cstdio>
12 #include<algorithm>
13 #include<iostream>
14 #include<vector>
15 #include<queue>
16 #include<cstring>
17 using namespace std;
18 
19 const int mx=100005;
20 long long b[mx],c[mx];
21 
22 
23 int main()
24 {
25     int t;
26     scanf("%d",&t);
27     while (t--)
28     {
29         int n;
30         scanf("%d",&n);
31         for (int i=1;i<=n;i++) scanf("%I64d",&b[i]);
32         for (int i=1;i<=n;i++) scanf("%I64d",&c[i]);
33         if (b[1]!=c[1])
34         {
35             printf("0
");
36             continue;
37         }
38         long long ans=1;
39         for (int i=2;i<=n;i++)
40         {
41             if ((b[i]<b[i-1]&&c[i]==c[i-1])||(c[i]>c[i-1]&&b[i]==b[i-1]))
42             continue;
43             if (b[i]==b[i-1]&&c[i]==c[i-1])
44             {
45                 if (c[i]-b[i]+1<i)
46                 {
47                     ans=0;
48                     break;
49                 }
50                 ans=(ans*(c[i]-b[i]+2-i))%998244353;
51                 continue;
52             }
53             ans=0;
54             break;
55         }
56         printf("%I64d
",ans);
57     }
58 
59 }
原文地址:https://www.cnblogs.com/pblr/p/5680321.html