Advertisement
rajeshinternshala

Untitled

Oct 12th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. int getChannelRating(vector<int> &views)
  2. {
  3.     long long ans = 0;
  4.     long long modd = 1e9 + 7;
  5.     map<long long, long long> m;
  6.     m[0]++;
  7.     long long p = 0;
  8.     vector<long long> pre(views.size());
  9.     for (int i = 0; i < views.size(); i++)
  10.     {
  11.         p ^= views[i];
  12.         if (i >= 2)
  13.         {
  14.             ans += m[p];
  15.             ans %= modd;
  16.             if (pre[i - 1] == p)
  17.             {
  18.                 ans--;
  19.                 ans %= modd;
  20.             }
  21.         }
  22.         m[p]++;
  23.         pre[i] = p;
  24.     }
  25.     return ans;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement