Advertisement
tepyotin2

Three Days Ago

Jul 7th, 2025
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. string s;
  8.  
  9. int main(){
  10.     // freopen("threedaysago.in", "r", stdin);
  11.  
  12.     cin >> s;
  13.     ll flag = 0;
  14.     ll res = 0;
  15.     map<ll, ll> mp;
  16.     mp[0] = 1;
  17.     for(int i=0; i<s.size(); i++){
  18.         flag^=(1<<(s[i]-'0'));
  19.         /*
  20.         get binary values which change according to
  21.         the new string that is being considered from the string
  22.         to process as decimal numbers which will be unique depending
  23.         on the binary values
  24.         */
  25.         res+=mp[flag];
  26.         mp[flag]++;
  27.         /*
  28.         calculation similar to prefix sum/map use in past problems
  29.         where substrings need to be checked for amount that are valid
  30.         to a certain case
  31.         */
  32.     }
  33.     cout << res << '\n';
  34.  
  35.     return 0;
  36. }
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement