没拿过 CSP-J 1= 选手
qq号:3776879953
祭坛
200紫 祭@251209 历史的研究又交了一遍
800AC 祭@260113 P14829 [THUPC 2026 初赛] Asian Soulv
365 days@260517
金勾祭@260519
100黑祭@260531
900AC 祭@260619 P8419 [THUPC 2022 决赛] riapq
400d 祭@??
500d 祭@261027
first 不看题解 *3500 CF2084H Turtle and Nediam 2 @ 261027@1028
https://qoj.ac/problem/5246/statement/zh_cn https://qoj.ac/problem/857/statement/zh_cn
// 13.37
// 20.17
#include<iostream>
#include<utility>
using namespace std;
typedef pair<int, int> pii;
const int N = 2e6 + 10;
const int MOD = 1e9 + 7;
inline void add(int &a, int b) { a += b; (a >= MOD) && (a -= MOD); }
int T, n;
int a[N], f[N][2];
pii sta[2][N]; int tp[2], s[2], c[2], ls[2], c0[2], id[2];
void clear() {
tp[0] = tp[1] = s[0] = s[1] = c[0] = c[1] = id[0] = id[1] = 0;
for(int i = 1; i <= n; i++) f[i][0] = f[i][1] = 0;
}
int main() {
cin >> T;
while(T--) {
cin >> n; clear();
for(int i = 1; i <= n; i++) { char c; cin >> c; a[n - i + 1] = (c == '1'); }
for(int i = n; i >= 1; i--) {
int x = a[i]; ++c[x];
f[i][x ^ 1] = f[i + 1][x ^ 1];
if(i == n || a[i + 1] != x) {
sta[x][++tp[x]] = pii(i, 1 - ++id[x]);
if(id[x] == 1) ls[x] = i;
} else {
sta[x][tp[x]].second++;
if(tp[x] > 1) add(s[x], MOD - f[sta[x][tp[x] - 1].first - sta[x][tp[x] - 1].second + sta[x][tp[x]].second][x ^ 1]);
}
if(sta[x][tp[x]].first == ls[x]) ++c0[x];
if(tp[x] > 1 && sta[x][tp[x]].second == sta[x][tp[x] - 1].second) sta[x][tp[x] - 1] = sta[x][tp[x]], --tp[x];
add(s[x], f[i][x ^ 1]);
f[i][x] = s[x] + ;
}
cout << f[1][a[1]] << '\n';
}
return 0;
}