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;
  const long long mod = 1000000007;
  long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
  const unsigned gen_seed =
      std::chrono::system_clock::now().time_since_epoch().count();
  std::mt19937_64 gen(gen_seed);
  int main() {
    int ta;
    scanf("%d", &ta);
    for (int ifa = 0; ifa < ta; ifa++) {
      int n;
      scanf("%d", &n);
      std::vector<int> a(n);
      for (int i = 0; i < n; i++) scanf("%d", &a[i]);
      for (int i = 0; i < n; i++) a[i] = abs(a[i]);
      const int INF = 2e9;
      std::vector<int> dm(n, INF);
      std::vector<int> dp(n, INF);
      std::vector<int> pp(n);
      std::vector<int> pm(n);
      dm[0] = -INF;
      dp[0] = -INF;
      pp[0] = 1;
      pm[0] = -1;
      for (int i = 0; i < n - 1; i++) {
        int to = a[i + 1];
        if (-to >= -a[i] && dm[i + 1] > dm[i]) {
          dm[i + 1] = dm[i];
          pm[i + 1] = -1;
        }
        if (-to >= dm[i] && dm[i + 1] > -a[i]) {
          dm[i + 1] = -a[i];
          pm[i + 1] = -1;
        }
        if (to >= -a[i] && dp[i + 1] > dm[i]) {
          dp[i + 1] = dm[i];
          pp[i + 1] = -1;
        }
        if (to >= dm[i] && dp[i + 1] > -a[i]) {
          dp[i + 1] = -a[i];
          pp[i + 1] = -1;
        }
        if (-to >= a[i] && dm[i + 1] > dp[i]) {
          dm[i + 1] = dp[i];
          pm[i + 1] = 1;
        }
        if (-to >= dp[i] && dm[i + 1] > a[i]) {
          dm[i + 1] = a[i];
          pm[i + 1] = 1;
        }
        if (to >= a[i] && dp[i + 1] > dp[i]) {
          dp[i + 1] = dp[i];
          pp[i + 1] = 1;
        }
        if (to >= dp[i] && dp[i + 1] > a[i]) {
          dp[i + 1] = a[i];
          pp[i + 1] = 1;
        }
      }
      int cur = n - 1;
      int sg = 0;
      if (dp[n - 1] != INF) sg = 1;
      if (dm[n - 1] != INF) sg = -1;
      if (sg == 0)
        printf("NO\n");
      else {
        while (cur >= 0) {
          a[cur] *= sg;
          if (sg > 0)
            sg = pp[cur--];
          else
            sg = pm[cur--];
        }
        printf("YES\n");
        for (int i = 0; i < n; i++) printf("%d ", a[i]);
        printf("\n");
      }
    }
  }
  