#ifndef NOSTDCPP #include <bits/stdc++.h> #else #include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstring> #include <cstdio> #include <deque> #include <exception> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <iterator> #include <list> #include <map> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #endif # ifdef Linux_System # define getchar getchar_unlocked # define putchar putchar_unlocked # endif # define RESET(_) memset(_, 0, sizeof(_)) # define RESET_(_, val) memset(_, val, sizeof(_)) # define fi first # define se second # define pb push_back # define midf(x, y) ((x + y) >> 1) # define DXA(_) ((_ << 1)) # define DXB(_) ((_ << 1) | 1) # define next __Chtholly__ # define x1 __Mercury__ # define y1 __bbtl04__ # define index __ikooo__ using namespace std; typedef long long ll; typedef vector <int> vi; typedef set <int> si; typedef pair <int, int> pii; typedef long double ld; const int MOD = 1e9 + 7; const int maxn = 200009; const int maxm = 300009; const double pi = acos(-1.0); const double eps = 1e-6; ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;} template <class T> inline bool scan_d(T & ret) { char c; int sgn; if(c = getchar(), c == EOF)return false; while(c != '-' && (c < '0' || c > '9'))c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while(c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return true; } #ifdef Cpp11 template <class T, class ... Args> inline bool scan_d(T & ret, Args & ... args) { scan_d(ret); scan_d(args...); } #define cin.tie(0); cin.tie(nullptr); #define cout.tie(0); cout.tie(nullptr); #endif inline bool scan_ch(char &ch) { if(ch = getchar(), ch == EOF)return false; while(ch == ' ' || ch == '\n')ch = getchar(); return true; } inline void out_number(ll x) { if(x < 0) { putchar('-'); out_number(- x); return ; } if(x > 9)out_number(x / 10); putchar(x % 10 + '0'); } struct node { int ma, tag; }tree[maxn << 2]; void pushup(int p, int l, int r) { if(l < r) { tree[p].ma = max(tree[DXA(p)].ma, tree[DXB(p)].ma); } } void pushdown(int p, int l, int r) { if(~ tree[p].tag) { tree[DXA(p)].ma = tree[p].ma; tree[DXA(p)].tag = tree[p].tag; tree[DXB(p)].ma = tree[p].ma; tree[DXB(p)].tag = tree[p].tag; tree[p].tag = -1; } } void pre(int l, int r, int p) { tree[p].ma = -1; tree[p].tag = -1; if(l == r) { scanf("%d", &tree[p].ma); return ; } int mid = midf(l, r); pre(l, mid, DXA(p)); pre(mid + 1, r, DXB(p)); pushup(p, l, r); } int l, r, n, m; int x; void update_1(int nl, int nr, int p) { if(l <= nl && nr <= r) { tree[p].tag = x; tree[p].ma = x; return ; } pushdown(p, nl, nr); int mid = midf(nl, nr); if(l <= mid) update_1(nl, mid, DXA(p)); if(mid < r) update_1(mid + 1, nr, DXB(p)); pushup(p, nl, nr); } void update_2(int nl, int nr, int p) { if(l <= nl && nr <= r) { if(tree[p].ma <= x) return ; if(~ tree[p].tag) { tree[p].tag = __gcd(x, tree[p].ma); tree[p].ma = tree[p].tag; return ; } } pushdown(p, nl, nr); int mid = midf(nl, nr); if(l <= mid) update_2(nl, mid, DXA(p)); if(mid < r) update_2(mid + 1, nr, DXB(p)); pushup(p, nl, nr); } void query_max(int nl, int nr, int p) { if(~ tree[p].tag) { for(int i = nl; i <= nr; i ++) printf("%d ", tree[p].tag); return ; } if(nl == nr) { printf("%d ", tree[p].ma); return ; } pushdown(p, nl, nr); int mid = midf(nl, nr); query_max(nl, mid, DXA(p)); query_max(mid + 1, nr, DXB(p)); } int main() { int T, type; scanf("%d", &T); while(T --) { scanf("%d", &n); pre(1, n, 1); scanf("%d", &m); while(m --) { scanf("%d %d %d %d", &type, &l, &r, &x); switch(type) { case 1: update_1(1, n, 1); break; case 2: update_2(1, n, 1); break; default: assert(type == 1 || type == 2); } } query_max(1, n, 1); puts(""); } return 0; }
|