답안 #771521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771521 2023-07-03T05:49:17 Z taitruong270 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
1 ms 212 KB
/*==============================================================================================================
         __                    __                                             _____     ______    _______
        |  |                  |  |                                           /  __ \   / _____|  / ______|     
      __|  |__              __|  |__                                         |_|  | |  | |       | |  
     |__|   __|            |__|   __|                                             | |  | |____   | |_____ 
        |  |    _____   _     |  |    ____  __  __  ____    _____    _____       / /   \ ___  \  |  ___  \
        |  |   /  _  \ | |    |  |   /  _/ | | | | /  _  \ /  __ \  /  _  \     / /         | |  | |   | |
        |  |_  | |_| | | |    |  |_  | |   | |_| | | |_| | | |  | | | |_| |    / /___   ____| |  | |___| |
        \____\ \____/| |_|    \____\ |_|   \_____/ \_____/ |_|  |_| \____ |   |______| |______/  \_______/
                                                                        | |
                                                                      __/ |
                                                                     |___/  
                                        Pratice, practice, and practice
I hated every minute of training, but I said, ‘Don’t quit. Suffer now and live the rest of your life as a champion.' - Mohamed Ali 
                              You may not be the best, but must be the most effort
                                          Noi dau + Suy ngam = Tien bo 
==============================================================================================================*/
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const ll mod = 1e9+7;

struct node 
{
    ll l, r, sum, lazy;
    node *leftchild, *rightchild;

    node(ll _l, ll _r)
    {
        l=_l;
        r=_r;
        sum=0;
        lazy=0;
        leftchild=rightchild=nullptr;
    }

    ~node()
    {
        delete leftchild;
        delete rightchild;
    }

    void extend()
    {
        if (l!=r)
        {
            ll mid=(l+r)/2;
            if (leftchild==nullptr) leftchild=new node(l, mid);
            if (rightchild==nullptr) rightchild=new node(mid+1, r);
        }
    }

    void down()
    {
        if (lazy!=0)
        {
            sum=(r-l+1)*lazy;
            if (l!=r)
            {
                extend();
                leftchild->lazy=lazy;
                rightchild->lazy=lazy;
            }   
            lazy=0;
        }
    }

    void update(ll u, ll v, ll val)
    {
        if (l>v || r<u || u>v) return;   
        if (u<=l && r<=v) 
        {
            lazy=val;
            down();   
            return;
        }
        extend();
        down();
        leftchild->update(u, v, val);
        rightchild->update(u, v, val);
        sum = leftchild->sum + rightchild->sum;  
    }

    ll query(ll u, ll v)
    {
        if (l>v || r<u || u>v) return 0;
        if (u<=l && r<=v) return sum;
        extend();
        down();
        return leftchild->query(u, v)+rightchild->query(u, v);
    }
};
node root(1, 1e9+10);
ll q, c;

void solve()
{
    cin>>q;
    while (q--)
    {
        ll type, l, r; cin>>type>>l>>r; l+=c; r+=c; assert(l<=1e9 && r<=1e9);
        if (type==1) c=root.query(l, r), cout<<c<<endl;
        else root.update(l, r, 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    clock_t start = clock();
    
    solve();
    clock_t end = clock();
    cerr<<"Time: "<<fixed<<setprecision(10)<<double(end-start)/double(CLOCKS_PER_SEC)<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -