fork download
  1. //Bismillahir Rahmanir Rahim
  2. /******Harun Or Rashid******/
  3. /***********Template Starts Here***********/
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<cstring>
  7. #include<cmath>
  8. #include<cctype>
  9. #include<cstdlib>
  10. #include<cassert>
  11. #include<string>
  12. #include<vector>
  13. #include<set>
  14. #include<stack>
  15. #include<queue>
  16. #include<map>
  17. #include<algorithm>
  18. using namespace std;
  19.  
  20. #define MEM(a,b) memset(a,b,sizeof(a))
  21. #define CLR(a) memset(a,0,sizeof(a))
  22. #define MAX(a,b) ((a)>(b)?(a):(b))
  23. #define MIN(a,b) ((a)>(b)?(b):(a))
  24. #define ABS(a) ((a)>0? (a):(-(a)))
  25. #define SQ(a) ((a)*(a))
  26. #define SZ(a) (int)a.size()
  27. #define FORN(i,n) for(i=1;i<=n;i++)
  28. #define FORAB(i,a,b) for(i=a;i<=b;i++)
  29. #define ALL(V) V.begin(),V.end()
  30. #define pb(a) push_back(a)
  31. #define pr(a) cout<<a<<endl
  32. #define SQR(a) ((a)*(a))
  33. #define pf printf
  34. #define sf scanf
  35. #define swap(a,b) (a ^= b, b ^= a, a ^= b)
  36. #define PI acos(-1)
  37. #define x first
  38. #define y second
  39. #define eps 1e-7
  40.  
  41. typedef int D;
  42. typedef long long int LLD;
  43. typedef unsigned long long int LLU;
  44. typedef vector<D> VI;
  45. typedef set<D> SI;
  46. typedef vector<D>::iterator Viti;
  47.  
  48. /***********Template Ends Here***********/
  49.  
  50. int main()
  51. {
  52. int T,i,n,p,q,j,x,flag[62501];
  53. cin>>T;
  54. for(i=1; i<=T; i++)
  55. {
  56. cin>>n>>p>>q;
  57. memset(flag,0,sizeof flag);
  58. for(j=1; j<=p+1; j++)
  59. {
  60. cin>>x;
  61. flag[x]=j;
  62. }
  63. vector<int>lcs;
  64. for(j=1; j<=q+1; j++)
  65. {
  66. cin>>x;
  67. if(flag[x]==0) continue;
  68. if(lcs.size()==0 || lcs.back()<flag[x])
  69. lcs.pb(flag[x]);
  70. else *lower_bound(lcs.begin(),lcs.end(),flag[x])=flag[x];
  71. }
  72. printf("Case %d: %d\n",i,lcs.size());
  73. }
  74. return 0;
  75. }
  76.  
  77.  
Success #stdin #stdout 0s 3604KB
stdin
1

3 6 7

1 7 5 4 8 3 9

1 4 3 5 6 2 8 9
stdout
Case 1: 4