Has anybody noticed that submission 222222222 is coming? I know it's not as news-breaking as 200000000, but nonetheless, a neat number! Let's hope the 2x9th submission is accepted 😎

# | User | Rating |
---|---|---|

1 | tourist | 3775 |

2 | Benq | 3724 |

3 | orzdevinwang | 3697 |

4 | Radewoosh | 3651 |

5 | jiangly | 3632 |

6 | cnnfls_csy | 3620 |

7 | -0.5 | 3545 |

8 | inaFSTream | 3478 |

9 | fantasy | 3468 |

10 | Rebelz | 3415 |

# | User | Contrib. |
---|---|---|

1 | adamant | 178 |

2 | awoo | 167 |

3 | BledDest | 165 |

4 | Um_nik | 163 |

5 | maroonrk | 162 |

6 | SecondThread | 159 |

7 | nor | 158 |

8 | -is-this-fft- | 153 |

9 | kostka | 146 |

10 | TheScrasse | 144 |

`n = -n`

, `n *= -1`

, or other methods? If so, suggest some methods down below.

I am trying to solve 165C using binary search, but it is getting TLE. Can anyone help?

Here's my code: 208389930

```
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k;
ll pre[100005];
string s;
ll bs1(ll lo){
ll l = lo, r = n, mid;
while (l <= r){
mid = (l + r) / 2;
if (pre[mid] - pre[lo-1] <= k){
l = mid + 1;
} else {
r = mid - 1;
}
}
return r;
}
ll bs2(ll lo){
ll l = lo, r = n, mid;
while (l <= r){
mid = (l + r) / 2;
if (pre[mid] - pre[lo-1] >= k){
r = mid - 1;
} else {
l = mid + 1;
}
}
return l;
}
signed main(){
ll i, res;
cin >> k >> s;
n = s.size();
s = " " + s;
pre[0] = 0;
for (i = 1; i <= n; i++){
pre[i] = pre[i-1] + s[i] - '0';
}
res = 0;
for (i = 1; i <= n; i++){
res += bs1(i) - bs2(i) + 1;
}
cout << res;
}
```

Codeforces (c) Copyright 2010-2023 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/03/2023 18:00:07 (l1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|