답안 #918693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918693 2024-01-30T09:19:05 Z AndrijaM 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
10 ms 49752 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = (int)3e5+10;
int mx=1e9, st[maxn*40], lz[maxn*40];
int L[maxn*40], R[maxn*40], IND = 1, q,c;

void prop(int pos,int l,int r)
{
    if(lz[pos])
    {
        st[pos]+=lz[pos]*(r-l+1);
        if(l!=r)
        {
            if(!L[pos])L[pos]=++IND;
            if(!R[pos])R[pos]=++IND;
            lz[L[pos]]=lz[R[pos]]=lz[pos];
        }
        lz[pos]=0;
    }
}

void u(int i,int j,int l,int r,int val,int pos)
{
    prop(pos,l,r);
	if(i<=l && r<=j)
    {
        st[pos]+=(r-l+1)*val;
        if(l!=r)
        {
            if(!L[pos])L[pos]=++IND;
            if(!R[pos])R[pos]=++IND;
            lz[L[pos]]=lz[R[pos]]=val;
        }
        return ;
    }
    if(i>r || j<l)
    {
        return ;
    }
    int mid=(l+r)/2;
    if(i<=mid)
    {
        if(!L[pos])L[pos]=++IND;
        u(i,j,l,mid,val,L[pos]);
    }
    if(j>mid)
    {
        if(!R[pos])R[pos]=++IND;
        u(i,j,mid+1,r,val,R[pos]);
    }
    st[pos]=st[L[pos]]+st[R[pos]];
}

int query(int i,int j,int l,int r,int pos)
{
	prop(pos,l,r);
	if(i<=l && r<=j)
    {
        return st[pos];
    }
    if(i>r || j<l)
    {
        return 0;
    }
    int mid=(l+r)/2;
    return query(i,j,l,mid,L[pos])+query(i,j,mid+1,r,R[pos]);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> q;
    memset(lz,0,sizeof(lz));
    while(q--){
        int t, x, y; cin >> t >> x >> y; x+=c, y+=c;
        if(t==1) c = query(x,y,1,mx,1), cout << c <<endl;
        else u(x,y,1,mx,1,1);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 49752 KB Output is correct
2 Correct 9 ms 49500 KB Output is correct
3 Incorrect 9 ms 49620 KB Output isn't correct
4 Halted 0 ms 0 KB -