/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.324 MiB
#2 Wrong Answer 2ms 2.324 MiB
#3 Accepted 217ms 17.633 MiB
#4 Accepted 209ms 16.379 MiB
#5 Accepted 180ms 18.195 MiB
#6 Wrong Answer 179ms 18.246 MiB

Code


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'

const int N = 5e5 + 9;

struct node
{
  int prefix, suffix, sorted;
};

node t[4 * N];
int lazy[4 * N];
int a[N];

node merge(node l, node r)
{ // what question need ??
//   if (l.prefix == -1)
//     return r;
//   if (r.prefix == -1)
//     return l;
  node ans;
  ans.prefix = l.prefix;
  ans.suffix = r.suffix;
//   if (l.suffix <= r.prefix)
//   {
//     ans.sorted = max(l.sorted, r.sorted);
//   }
//   else
//   {

//     ans.sorted = 1;
//   }
  if(l.sorted==0 and r.sorted==0 and l.suffix <= r.prefix)
    ans.sorted = 0;
  else
    ans.sorted = 1;
  return ans;
}

void build(int n, int b, int e)
{

  if (b == e)
  {
    t[n].prefix = a[b];
    t[n].suffix = a[b];
    t[n].sorted = 0;
    return;
  }
  int mid = (b + e) / 2, l = 2 * n, r = 2 * n + 1;
  build(l, b, mid);
  build(r, mid + 1, e);
  t[n] = merge(t[l], t[r]);
}

void upd(int n, int b, int e, int i, int j, int v)
{

  if (e < i or j < b)
    return;
  if (b >= i and e <= j)
  {
    t[n].suffix = t[n].prefix = v;
    t[n].sorted = 0;
    return;
  }
  int mid = (b + e) / 2, l = 2 * n, r = 2 * n + 1;
  upd(l, b, mid, i, j, v);
  upd(r, mid + 1, e, i, j, v);
  t[n] = merge(t[l], t[r]);
}

int query(int n, int b, int e, int i, int j)
{
  if (e < i or j < b)
    return 0; // resutl
  if (b >= i and e <= j)
  {
    return t[n].sorted; // result
  }
  int mid = (b + e) / 2, l = 2 * n, r = 2 * n + 1;
  return max(query(l, b, mid, i, j),query(r, mid + 1, e, i, j)); // result
}

void solve()
{
  int n, q;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  build(1, 1, n);
  cin >> q;
  while (q--)
  {
    int type;
    cin >> type;
    if (type == 1)
    {
      int i, x;
      cin >> i >> x;
      upd(1, 1, n, i, i, x);
    }
    else
    {
      int l, r;
      cin >> l >> r;

      int ans = query(1, 1, n, l, r);
      if (ans>= 1)
      {
        cout << "NO\n";
      }
      else
        cout << "YES\n";
      // cout << ans.value << endl;
    }
  }
}

int32_t main()
{

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  for (int j = 1; j <= t; j++)
  {
    // cout << "Case " << j << ":\n";
    solve();
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-18 18:59:34
Judged At
2024-11-11 03:07:27
Judged By
Score
40
Total Time
217ms
Peak Memory
18.246 MiB