3 条题解
-
1
树状数组永远的概念神
#include <bits/stdc++.h> #define int long long #define pow_of_two(n) (n & -n == n) using namespace std; typedef pair<int , int> PII; const int N = 5e6 + 10; int n; int c[N]; int lowbit(int x) { return x & -x; } void add(int x , int k) { while (x <= n) { c[x] += k; x += lowbit(x); } } int query(int x) { int res = 0; while (x) { res += c[x]; x -= lowbit(x); } return res; } inline void solve() { int t; cin >> t; int sb = 1; while (t -- ) { cin >> n; string s; cin >> s; for (int i = 0 ; i < s.size() ; i ++ ) add(i + 1 , s[i] - '0'); int ans = 0 , temp; if (n & 1) temp = n / 2 + 1; else temp = n / 2; // cout << temp << endl; for (int i = 1 ; i <= temp + 1 ; i ++ ) ans = max(ans , query(i + temp - 1) - query(i - 1)); // cout << endl; printf("Case #%lld: %lld\n" , sb ++ , ans); memset(c , 0 , sizeof c); // cout << ans << endl; } } signed main() { ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0); solve(); return 0; }
信息
- ID
- 5395
- 时间
- 1500ms
- 内存
- 1024MiB
- 难度
- 2
- 标签
- 递交数
- 24
- 已通过
- 4
- 上传者