Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
- #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
- #define endl "\n"
- #define mn int main()
- #define frac() cout.unsetf(ios::floatfield);cout.precision(6);cout.setf(ios::fixed,ios::floatfield);
- const int mx=1e6+123;
- int s0[mx],s1[mx];
- mn
- {
- suni;
- int t; cin>>t;
- for(int j=1;j<=t;j++)
- {
- string s; cin>>s;
- ll k;cin>>k;
- ll n=s.size();
- for(int i=0;i<n;i++){
- s0[i+1]=(s[i]=='0')+s0[i];
- s1[i+1]=(s[i]=='1')+s1[i];
- }
- ordered_set p;
- map<ll,ll>cnt;
- ll ans=0;
- p.insert(0);
- cnt[0]++;
- for(int i=1;i<=n;i++){
- ll d= s0[i]-(k*s1[i]);
- ans+=p.order_of_key(d)+cnt[d];
- p.insert(d);
- cnt[d]++;
- }
- cout<<"Case "<<j<<": "<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement