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>
  using namespace std;
  long long dp[1000006][2];
  long long pre[1000006][2];
  void chkMinLog(long long& goal, long long t1, bool t2, bool curr) {
    if (dp[t1][t2] > goal) {
      dp[t1][t2] = goal;
      pre[t1][t2] = curr;
    }
  }
  void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n + 2);
    for (long long i = (1); i <= (n); i++) cin >> a[i];
    for (long long i = (1); i <= (n); i++)
      for (long long j = (0); j <= (1); j++) dp[i][j] = 1e18;
    a[0] = n + 1;
    dp[0][0] = dp[0][1] = -n - 1;
    for (long long i = (0); i <= (n - 1); i++)
      for (long long isPos = (0); isPos <= (1); isPos++) {
        long long sv = (isPos ? 1 : -1) * a[i], v = dp[i][isPos];
        if (-a[i + 1] > v) chkMinLog(sv, i + 1, false, isPos);
        if (a[i + 1] > v) chkMinLog(sv, i + 1, true, isPos);
        if (-a[i + 1] > sv) chkMinLog(v, i + 1, false, isPos);
        if (a[i + 1] > sv) chkMinLog(v, i + 1, true, isPos);
      }
    if (dp[n][0] <= n || dp[n][1] <= n) {
      cout << "YES" << endl;
      long long ti = n, ts = 0;
      if (dp[n][1] <= n) ts = 1;
      while (ti >= 1) {
        if (ts == 0) a[ti] = -a[ti];
        ts = pre[ti][ts], ti--;
      }
      for (long long i = (1); i <= (n); i++) cout << a[i] << " ";
      cout << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
  }
  