#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--){
int a, b;
cin >> a >> b;
while(min(a, b) != 0){
cout << 0 << 1;
a--;
b--;
}
while(a--){
cout << 0;
}
while(b--){
cout << 1;
}
cout << endl;
}
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int t;
cin >> t;
while(t--){
int len;
cin >> len;
string num;
cin >> num;
int numz = 0, numo = 0;
int res = 0;
res += len;
for(int i = 1; i < len; i++){
if(num[i] != num[i-1]){
res += i;
}
}
cout << res << endl;
}
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
#define int long long
int arr[200010];
signed main()
{
int t;
cin >> t;
while(t--){
memset(arr, 0, sizeof arr);
int len;
cin >> len;
int endCnt = 0;
int sum = 0;
for(int i = 0; i < len; i++){
cin >> arr[i];
sum += arr[i];
if(arr[i] != 0){
endCnt = i;
}
}
if(sum != 0){
cout << "No\n";
continue;
}
int flag = 0;
int pre = 0;
int now = arr[0];
for(int i = 0; i <= endCnt; i++){
now = arr[i];
int del = now + pre;
if(del < 0){
flag = 1;
break;
}
if(i != endCnt){
//cout << i << ' ' << endCnt << ' ' <<"error\n";
if(del == 0){
flag = 1;
break;
}
}
pre = del;
}
if(flag){
cout << "No\n";
}
else{
cout << "Yes\n";
}
}
return 0;
}
D
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
const int w = 200005, N = w * 2;
int n, m;
int h[w], e[N], ne[N], idx;
int l[w], r[w];
LL option[w];
int resarr[w];
int dfs(int u)
{
for(int i = h[u]; ~i;i = ne[i]){
int j = e[i];
option[u] += dfs(j);
resarr[u] += resarr[j];
}
if(option[u] >= l[u]){
resarr[u] --;
option[u] = min((LL)r[u], option[u]);
}
else{
option[u] = r[u];
}
return option[u];
}
int main()
{
int T;
cin >> T;
while(T--){
cin >> n;
//init
for(int i = 0;i <= n;i++){
h[i] = -1;
option[i] = 0;
resarr[i] = 1;
}
idx = 0;
for(int i = 2;i <= n;i++){
int a;
cin >> a;
e[idx] = i;
ne[idx] = h[a];
h[a] = idx++;
}
for(int i = 1;i <= n;i++){
cin >> l[i] >> r[i];
}
dfs(1);
cout << resarr[1] << endl;
}
return 0;
}