description: You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).
  
  Let's call an array a bipartite if the following undirected graph is bipartite:
  
    * the graph consists of n vertices; 
    * two vertices i and j are connected by an edge if i < j and a_i > a_j. 
  
  
  
  Your task is to find a bipartite array of integers a of size n, such that a_i = p_i or a_i = -p_i, or report that no such array exists. If there are multiple answers, print any of them.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — the number of test cases.
  
  The first line of each test case contains a single integer n (1 ≤ n ≤ 10^6) — the size of the permutation.
  
  The second line contains n integers p_1, p_2, ..., p_n.
  
  The sum of n over all test cases doesn't exceed 10^6.
  
  Output
  
  For each test case, print the answer in the following format. If such an array a does not exist, print "NO" in a single line. Otherwise, print "YES" in the first line and n integers — array a in the second line.
  
  Example
  
  Input
  
  
  4
  3
  1 2 3
  6
  1 3 2 6 5 4
  4
  4 1 3 2
  8
  3 2 1 6 7 8 5 4
  
  
  Output
  
  
  YES
  1 2 3
  NO
  YES
  -4 -1 -3 -2
  YES
  -3 -2 1 6 7 -8 -5 -4
solution: #include <bits/stdc++.h>
  const int INF = 2e9;
  inline int Max(const int &a, const int &b) { return a > b ? a : b; }
  inline int Min(const int &a, const int &b) { return a > b ? b : a; }
  inline int read() {
    int f = 1, x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
      if (ch == '-') f = -1;
      ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
      x = (x << 1) + (x << 3) + (ch ^ 48);
      ch = getchar();
    }
    return x * f;
  }
  using namespace std;
  const int N = 1e6 + 7;
  int T, n;
  int p[N], b[N];
  struct jgt {
    int j, k, ls, tp;
  } q[N * 4];
  int cnt;
  vector<int> f[N];
  void dfs(int id, int i) {
    if (!i) return;
    b[i] = q[id].tp * p[i];
    dfs(q[id].ls, i - 1);
  }
  int a, j, k;
  int ax, _ax, xa, x_a;
  int axid, _axid, xaid, x_aid;
  void solve() {
    n = read();
    for (int i = 1; i <= n; ++i) p[i] = read();
    for (int i = 1; i <= n; ++i) f[i].clear();
    q[cnt = 1] = {-p[1], -INF, 0, -1};
    f[1].push_back(1);
    for (int i = 2; i <= n; ++i) {
      if (f[i - 1].empty()) {
        puts("NO");
        return;
      }
      a = p[i];
      ax = _ax = xa = x_a = INF;
      axid = _axid = xaid = x_aid = 0;
      for (int id : f[i - 1]) {
        j = q[id].j, k = q[id].k;
        if (k < -a) {
          if (j < -a) {
            if (k < _ax) _ax = k, _axid = id;
          } else {
            if (j < x_a) x_a = j, x_aid = id;
          }
        }
        if (k < a) {
          if (j < a) {
            if (k < ax) ax = k, axid = id;
          } else {
            if (j < xa) xa = j, xaid = id;
          }
        }
      }
      if (ax < INF) {
        q[++cnt] = {a, ax, axid, 1};
        f[i].push_back(cnt);
      }
      if (xa < INF) {
        q[++cnt] = {xa, a, xaid, 1};
        f[i].push_back(cnt);
      }
      if (_ax < INF) {
        q[++cnt] = {-a, _ax, _axid, -1};
        f[i].push_back(cnt);
      }
      if (x_a < INF) {
        q[++cnt] = {x_a, -a, x_aid, -1};
        f[i].push_back(cnt);
      }
    }
    if (f[n].empty()) {
      puts("NO");
    } else {
      puts("YES");
      dfs(f[n][0], n);
      for (int i = 1; i <= n; ++i) printf("%d ", b[i]);
      puts("");
    }
  }
  int main() {
    T = read();
    for (int i = 1; i <= T; ++i) {
      solve();
    }
    return 0;
  }
  