fork download
  1. #include"bits/stdc++.h"
  2.  
  3. using namespace std;
  4. #define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
  5. #define i64 int64_t
  6. #define deb(x) cout<<"["<<#x<<"="<<x<<"]"<<"\n"
  7. #define pb push_back
  8. int main()
  9. {
  10. fast;
  11. int t;
  12. cin>>t;
  13. while(t--)
  14. {
  15. int n,q;
  16. cin>>n>>q;
  17. vector<int>a(n);
  18. for(auto& i:a)
  19. {
  20. cin>>i;
  21. }
  22. int fin=[&]()->int{
  23. int ans=1;
  24. for(i64 i=0;i<a.size()-1;++i)
  25. {
  26. if(a[i]!=a[i+1])
  27. {
  28. ans++;
  29. }
  30. }
  31. return ans;
  32. }();
  33. vector<int>ans;
  34. while(q--)
  35. {
  36. i64 x,y;
  37. cin>>x>>y;
  38. vector<int>cache=a;
  39. a[x-1]=y;
  40. if(x!=0&&a[x-1]==a[x-2]&&cache[x-1]!=cache[x-2])
  41. {
  42. fin-=1;
  43. // cout<<fin<<"\n";
  44. }
  45. if(x!=n&&a[x-1]==a[x]&&cache[x-1]!=cache[x])
  46. {
  47. fin-=1;
  48. // cout<<fin<<"\n";
  49. }
  50. if(x!=0&&a[x-1]!=a[x-2]&&cache[x-1]==cache[x-2])
  51. {
  52. fin+=1;
  53. // cout<<fin<<"\n";
  54. }
  55. if(x!=n&&a[x-1]!=a[x]&&cache[x-1]==cache[x])
  56. {
  57. fin+=1;
  58. // cout<<fin<<"\n";
  59. }
  60. ans.pb(fin);
  61. }
  62. for(auto i:ans)
  63. {
  64. cout<<i<<"\n";
  65. }
  66. cout<<"\n";
  67. }
  68. return 0;
  69. }
Time limit exceeded #stdin #stdout 5s 527548KB
stdin
Standard input is empty
stdout
Standard output is empty