Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: compounding
- * created: 2024-11-13 17:00:06
- **/
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- #define f first
- #define s second
- #define yes cout << "YES" << endl
- #define no cout << "NO" << endl
- #define endl "\n"
- const int mod = 1000000007;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- void solve()
- {
- int n, val;
- cin >> n >> val;
- vi arr(n);
- int cnt_val = 0;
- for (auto &x : arr)
- {
- cin >> x;
- if (x == val)
- {
- cnt_val++;
- }
- }
- // TODO: Split the array into segments separated by val
- // and find the maximum frequency of any element in any segment
- int maxcnt = 0;
- map<int, int> freq;
- for (int i = 0; i < n; i++)
- {
- if (arr[i] == val)
- {
- freq.clear();
- }
- else
- {
- freq[arr[i]]++;
- if (freq[arr[i]] > maxcnt)
- {
- maxcnt = freq[arr[i]];
- }
- }
- }
- int final = cnt_val + maxcntt;
- cout << final << endl;
- return;
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment