fork download
  1. // #include <bits/stdc++.h>
  2. // using namespace std;
  3. // #define ll int
  4. // const ll MAX = 100004;
  5. // const ll MAX1 =100005;
  6. // ll tree[MAX], p[MAX1], ans[MAX], a[MAX];
  7. // pair <int, pair<int, int> > pr[MAX];
  8.  
  9.  
  10. // void update(ll idx, ll val)
  11. // {
  12. // while(idx < MAX)
  13. // {
  14. // tree[idx] += val;
  15. // idx += (idx & -idx);
  16. // }
  17. // }
  18.  
  19. // ll read(ll idx)
  20. // {
  21. // ll sum = 0;
  22. // while(idx > 0)
  23. // {
  24. // sum += tree[idx];
  25. // idx -= (idx & -idx);
  26. // }
  27. // return sum;
  28. // }
  29.  
  30. // int main()
  31. // {
  32. // ios_base::sync_with_stdio(false);
  33. // cin.tie(NULL);
  34. // ll t;
  35. // scanf("%d",&t);
  36. // ll k=1;
  37. // while(t--)
  38. // {
  39. // ll n, q, x;
  40. // scanf("%d%d", &n,&q);
  41. // for(ll i = 1;i <= n;++i)
  42. // scanf("%d", &a[i]);
  43. // //scanf("%d", &q);
  44. // for(ll i = 0;i < q;++i)
  45. // {
  46. // scanf("%d %d", &pr[i].second.first, &pr[i].first);
  47. // pr[i].second.second = i;
  48. // }
  49. // sort(pr, pr + q);
  50. // memset(p, -1, sizeof(p));
  51. // memset(tree, 0, sizeof(tree));
  52. // x = 0;
  53. // for(ll i = 1;i <= n;++i)
  54. // {
  55. // if(p[a[i]] != -1)
  56. // update(p[a[i]], -1);
  57.  
  58. // p[a[i]] = i;
  59. // update(i, 1);
  60.  
  61. // while(x < q and pr[x].first == i)
  62. // {
  63. // ans[pr[x].second.second] = read(pr[x].first) - read(pr[x].second.first-1);
  64. // x++;
  65. // }
  66. // }
  67. // printf("Case %d:\n",k);
  68. // for(ll i = 0;i < q;++i)
  69. // printf("%d\n", ans[i]);
  70. // k++;
  71. // }
  72. // return 0;
  73. // }
  74.  
  75. #include <bits/stdc++.h>
  76. using namespace std;
  77. int main()
  78. {
  79.  
  80. ios_base::sync_with_stdio(false);
  81. cin.tie(NULL);
  82. int a[100005];
  83. int b[100005];
  84. int n,q,i,t,r,l,j;
  85. scanf("%d",&t);
  86. for(j = 1; j <= t; j++)
  87. {
  88. scanf("%d%d",&n,&q);
  89. a[0] = -1;
  90. memset(b,0,sizeof(b));
  91. for(i = 1; i <= n; i++)
  92. {
  93. scanf("%d",&a[i]);
  94. if(a[i] == a[i-1])
  95. {
  96. b[i] = b[i-1];
  97. }
  98. else if(a[i] != a[i-1])
  99. {
  100. b[i] = b[i-1] + 1;
  101. }
  102. }
  103. printf("Case %d:\n",j);
  104.  
  105. while(q--)
  106. {
  107. scanf("%d%d",&l,&r);
  108. printf("%d\n",b[r]-b[l]+1);
  109. }
  110. }
  111. return 0;
  112. }
Success #stdin #stdout 0s 4380KB
stdin
2

5 3
1 2 2 4 5
1 2
1 5
4 5

3 1
1 1 1
1 3
stdout
Case 1:
2
4
2
Case 2:
1