답안 #872798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872798 2023-11-13T20:26:10 Z AndreiBOTO 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
2000 ms 348 KB
#include <bits/stdc++.h>

#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

///#include <tryhardmode>
///#include <GODMODE::ON>

///Hey I heard you like the wild ones
///Wild Ones - Flo Rida, Sia

using namespace std;

#define int long long

ifstream fin ("f.in");
ofstream fout ("f.out");

const int INF=1e9+5;

struct SegTree{
    int s;
    bool lazy;
    SegTree *left;
    SegTree *right;

    SegTree()
    {
        s=0;
        lazy=false;
        left=right=NULL;
    }
};

void propag(SegTree *aint,int st,int dr)
{
    if(aint==NULL)
        return ;
    else
    {
        if(aint->lazy)
        {
            aint->s=dr-st+1;
            if(st!=dr)
            {
                if(aint->left==NULL)
                    aint->left=new SegTree();
                if(aint->right==NULL)
                    aint->right=new SegTree();
                aint->left->lazy=true;
                aint->right->lazy=true;
            }
            aint->lazy=false;
        }
    }
}

void update(SegTree *aint,int st,int dr,int a,int b)
{
    propag(aint,st,dr);
    if(a<=st && dr<=b)
    {
        aint->lazy=true;
        aint->s+=dr-st+1;
        return ;
    }
    else
    {
        int mij=st+dr;
        mij/=2;
        if(aint->left==NULL)
            aint->left=new SegTree();
        if(aint->right==NULL)
            aint->right=new SegTree();
        if(a<=mij)
            update(aint->left,st,mij,a,b);
        if(mij<b)
            update(aint->right,mij+1,dr,a,b);
        aint->s=(aint->left->s)+(aint->right->s);
    }
}

int query(SegTree *aint,int st,int dr,int a,int b)
{
    if(aint==NULL)
        return 0;
    propag(aint,st,dr);
    if(a<=st && dr<=b)
        return aint->s;
    else
    {
        int kon=0;
        int mij=st+dr;
        mij/=2;
        if(a<=mij)
            kon+=query(aint->left,st,mij,a,b);
        if(mij<b)
            kon+=query(aint->right,mij+1,dr,a,b);
        return kon;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);

    SegTree *aint=new SegTree();
    int t,c=0;
    fin>>t;
    while(t--)
    {
        int type,x,y;
        fin>>type>>x>>y;
        if(type==1)
        {
            c=query(aint,1,INF,x+c,y+c);
            fout<<c<<"\n";
        }
        else
            update(aint,1,INF,x+c,y+c);
    }
    fin.close();
    fout.close();
    return 0;
}

Compilation message

apple.cpp:3: warning: ignoring '#pragma optimize GCC' [-Wunknown-pragmas]
    3 | #pragma optimize GCC ("Ofast")
      |
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2040 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -