#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int tree[N * 4];
int n, m;
int arr[N * 4];
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
void build_tree(int k, int l, int r) {
tree[k] = 0;
if (l >= r) {
tree[k] = arr[l];
return;
}
int mid = (l + r) / 2;
int ls = 2 * k;
int rs = 2 * k + 1;
build_tree(ls, l, mid), build_tree(rs, mid + 1, r);
if (tree[ls] == tree[rs])
tree[k] = max(tree[ls], tree[rs]);
}
void update_tree(int k, int l, int r, int op, int L, int R, int x) {
if (op == 1) {
if (L <= l && R >= r) {
tree[k] = x;
return;
}
} else {
if (L <= l && R >= r && tree[k]) {
if (tree[k] > x)
tree[k] = gcd(tree[k], x);
return;
}
}
if (tree[k]) {
int ls = 2 * k;
int rs = 2 * k + 1;
tree[ls] = tree[rs] = tree[k];
tree[k] = 0;
}
int mid = (l + r) / 2;
int ls = 2 * k;
int rs = 2 * k + 1;
if (L <= mid)
update_tree(ls, l, mid, op, L, R, x);
if (R > mid)
update_tree(rs, mid + 1, r, op, L, R, x);
if (tree[ls] == tree[rs])
tree[k] = max(tree[ls], tree[rs]);
}
void query_tree(int k, int l, int r) {
if (l >= r) {
printf("%d ", tree[k]);
return;
}
if (tree[k]) {
int ls = 2 * k;
int rs = 2 * k + 1;
tree[ls] = tree[rs] = tree[k];
tree[k] = 0;
}
int mid = (l + r) / 2;
int ls = 2 * k;
int rs = 2 * k + 1;
query_tree(ls, l, mid), query_tree(rs, mid + 1, r);
}
int main() {
int T;
scanf("%d", &T);
while (T -- ) {
scanf("%d", &n);
for (int i = 1; i <= n; i ++ )
scanf("%d", &arr[i]);
build_tree(1, 1, n);
scanf("%d", &m);
int op, L, R, x;
while (m -- ) {
scanf("%d%d%d%d", &op, &L, &R, &x);
update_tree(1, 1, n, op, L, R, x);
}
query_tree(1, 1, n);
puts("");
}
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
int tree[N * 10];
int n, h, w;
void build_tree(int k, int l, int r) {
tree[k] = 0;
if (l >= r) {
tree[k] = w;
return;
}
int mid = (l + r) / 2;
int ls = 2 * k;
int rs = 2 * k + 1;
build_tree(ls, l, mid), build_tree(rs, mid + 1, r);
tree[k] = max(tree[ls], tree[rs]);
}
int update_tree(int k, int l, int r, int x) {
if (l >= r) {
tree[k] -= x;
return l;
}
int res = 0;
int mid = (l + r) / 2;
int ls = 2 * k;
int rs = 2 * k + 1;
if (tree[ls] >= x)
res = update_tree(ls, l, mid, x);
else
res = update_tree(rs, mid + 1, r, x);
tree[k] = max(tree[ls], tree[rs]);
return res;
}
int main() {
while (~scanf("%d%d%d", &h, &w, &n)) {
if (h > n)
h = n;
build_tree(1, 1, h);
for (int i = 1; i <= n; i ++ ) {
int x;
scanf("%d", &x);
if (x > tree[1])
puts("-1");
else
printf("%d\n", update_tree(1, 1, h, x));
}
}
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int s[N];
int n;
void insert(int l, int r) {
s[l] += 1;
s[r + 1] -= 1;
}
int main() {
while (~scanf("%d", &n)) {
if (n == 0)
break;
memset(s, 0, sizeof s);
for (int i = 1; i <= n; i ++ ) {
int a, b;
scanf("%d%d", &a, &b);
insert(a, b);
}
for (int i = 1; i <= n; i ++ )
s[i] += s[i - 1];
for (int i = 1; i <= n; i ++ ) {
if (i != n)
printf("%d ", s[i]);
else
printf("%d\n", s[i]);
}
}
return 0;
}