版本比较
教练我也要玩崩铁
正文
增加 8 行删除 8 行
22 行未改动23242526272728293030313233333435363736373839394041424142434445464 行未改动22 行未改动while(_--) { cin >> str + 1; int n = strlen(str + 1); ll ans = 0; F(i, 1, n) F(i, 1, n) sum[i] = sum[i - 1] + (str[i] == '0' ? -1 : 1); F(i, 0, n) { while(top && sum[i] > sum[stk[top]]) while(top && sum[i] > sum[stk[top]]) a[stk[top--]] = i; stk[++top] = i; } } while(top) a[stk[top--]] = n + 1; F(i, 0, n) { while(top && sum[i] < sum[stk[top]]) b[stk[top--]] = i; while(top && sum[i] < sum[stk[top]]) b[stk[top--]] = i; stk[++top] = i; } } while(top) b[stk[top--]] = n + 1; F(i, 1, n) { if(str[i] == '0') F(i, 1, n) { if(str[i] == '0') ans += (ll)(a[i - 1] - i); else ans += (ll)(b[i - 1] - i); } cout << ans << '\n';4 行未改动