/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 53ms 61.691 MiB
#2 Wrong Answer 51ms 61.469 MiB
#3 Accepted 505ms 63.898 MiB
#4 Accepted 374ms 63.375 MiB
#5 Accepted 328ms 63.43 MiB
#6 Wrong Answer 328ms 63.414 MiB

Code

#include <bits/stdc++.h>

using namespace std;

#define db long long
#define ll long long
#define int ll
#define vi vector<int>
#define vs vector<string>
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define vps vector<pair<string, string>>
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pp(x) pop_back(x)
#define fr(cont) for (auto &i : (cont))
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()

const int N = 5e5 + 9;
int a[N];
struct ST {
    #define lc (n << 1)
    #define rc ((n << 1) + 1)
    int pre[4*N],suf[4*N],isSorted[4*N],lazy[4*N];
    ST(){
        memset(pre,0,sizeof(pre));
        memset(suf,0,sizeof(suf));
        memset(isSorted,0,sizeof(isSorted));//0-> not sorted,1->sorted
        memset(lazy,0,sizeof(lazy));
    }

    //parent er main value and child gulor lazy value update korar function
    inline void push(int n,int b,int e)//change this
    {
        if(lazy[n] == 0)
            return;
        pre[n] = lazy[n];
        suf[n] = lazy[n];
        isSorted[n] = 1;
        if(b != e)
        {
            lazy[lc] = lazy[n];//left child er lazy value update
            lazy[rc] = lazy[n];//right child er lazy value update
        }
        lazy[n] = 0;//jehetu parent node er child er lazy value update kore pelsi so parent er lazy 0 kore dite hobe
    }

    //value merge kore return korbe query er jonno
    inline int combine(int a,int b)//change this 
    {
        return min(a,b);
    }

    //parent node er value save korar function
    inline void pull(int n)//change this
    {
        if(isSorted[lc] and isSorted[rc] and pre[rc] >= suf[lc])
        {
            pre[n] = pre[lc];
            suf[n] = suf[rc];
            isSorted[n] = 1;
        }
        else
        {
            pre[n] = pre[lc];
            suf[n] = suf[rc];
            isSorted[n] = 0;
        }
    }

    //building the tree 
    inline void build(int n,int b,int e)
    {
        lazy[n] = 0;
        if(b == e)
        {
            pre[n] = suf[n] = a[b];
            isSorted[n] = 1;
            return;
        }
        int mid = (b+e)/2;
        build(lc,b,mid);
        build(rc,mid+1,e);
        pull(n);
    }

    //updating the value in a segment
    inline void upd(int n,int b,int e,int i,int j,int x)
    {
        push(n,b,e);
        if(e < i or b > j)
            return;
        if(b >= i and e <= j)
        {
            lazy[n] = x;
            push(n,b,e);//ei line na korleo hobe
            return;
        }
        int mid = (b+e)/2;
        upd(lc,b,mid,i,j,x);
        upd(rc,mid+1,e,i,j,x);
        pull(n);
    }

    inline int query(int n,int b,int e,int i,int j)
    {
        // cout << n << " " << b << " " << e << " " << isSorted[n] << endl;
        push(n,b,e);
        if(e < i or b > j)
            return 1e9;
        if(b >= i and e <= j)
            return isSorted[n];
        int mid = (b+e)/2;
        return combine(query(lc,b,mid,i,j),query(rc,mid+1,e,i,j));
    }
}t;

void solve()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    t.build(1,1,n);
    int q;
    cin>> q;
    while(q--)
    {
        int ty;
        cin>>ty;
        if(ty == 1)
        {
            int ind,x;
            cin>>ind >> x;
            t.upd(1,1,n,ind,ind,x);
        }
        else
        {
            int l,r;
            cin >> l >> r;
            // cout << t.query(1,1,n,l,r) <<endl;
            if(t.query(1,1,n,l,r))
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
    // t.build(1,1,n);//building the tree
    // t.upd(1,1,n,2,3,2);//udating the value of segment 2 to 3 with adding 1
    // cout << t.query(1,1,n,1,n);//printig the sum of semment 1 to n
}   

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // auto st = clock();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();

    // cerr << 1.0*(clock()-st)/CLOCKS_PER_SEC << endl;
    return 0;
}
/*Problem_link
     https://codeforces.com/contest/242/problem/E (Good One)
*/

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-18 18:44:05
Judged At
2024-11-11 03:07:31
Judged By
Score
40
Total Time
505ms
Peak Memory
63.898 MiB