Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #
  2. #include <iostream>
  3. #
  4. #include <string>
  5. #
  6. #include <cstring>
  7. #
  8. #include <vector>
  9. #
  10. #include <cmath>
  11. #
  12. #include <map>
  13. #
  14. #include <algorithm>
  15. #
  16. #include <climits>
  17. #
  18. using namespace std;
  19. #
  20. int S[1000005], cnt[1000005];
  21. #
  22. int main() {
  23. #
  24. int n,A,B,lp = 0,targ,cur = 0,ans = INT_MAX;
  25. #
  26. scanf("%d%d%d",&n,&A,&B);
  27. #
  28. targ = B-A+1;
  29. #
  30. if(targ > n) {
  31. #
  32. printf("-1\n");
  33. #
  34. return 0;
  35. #
  36. }
  37. #
  38. for(int rp=0;rp<n;++rp) {
  39. #
  40. scanf("%d",&S[rp]);
  41. #
  42. if(S[rp] < A || S[rp] > B) {
  43. #
  44. while(lp < rp) {
  45. #
  46. --cnt[S[lp]-A];
  47. #
  48. ++lp;
  49. #
  50. }
  51. #
  52. ++lp;
  53. #
  54. cur = 0;
  55. #
  56. continue;
  57. #
  58. }
  59. #
  60. int& v = cnt[S[rp]-A];
  61. #
  62. ++v;
  63. #
  64. if(v == 1) ++cur;
  65. #
  66. while(cur == targ) {
  67. #
  68. ans = min(ans,rp-lp+1);
  69. #
  70. int& k = cnt[S[lp]-A];
  71. #
  72. --k;
  73. #
  74. if(!k) --cur;
  75. #
  76. ++lp;
  77. #
  78. }
  79. #
  80. }
  81. #
  82. if(ans == INT_MAX) printf("-1\n");
  83. #
  84. else printf("%d\n",ans);
  85. #
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement