답안 #254074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254074 2020-07-29T10:27:44 Z test2 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
44 ms 1528 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (1 << 24);
int t, a, b, c;
int tree[N * 4];

void update(int node, int L, int R, int l, int r)
{
        if (l > r || l > R || r < L || tree[node] == R - L + 1)
                return;
        if (L >= l && R <= r)
        {
                tree[node] = R - L + 1;
                return;
        }
        int mid = (L + R) >> 1;
        update(node * 2 + 1, L, mid, l, r);
        update(node * 2 + 2, mid + 1, R, l, r);
        tree[node] = tree[node * 2 + 1] + tree[node * 2 + 2];
}

int query(int node, int L, int R, int l, int r)
{
        if (l > r || l > R || r < L)
                return 0;

        if (L >= l && R <= r)
        {
                return tree[node];
        }

        if (tree[node] == R - L + 1)
        {
                return min(r, R) - max(l, L) + 1;
        }

        int mid = (L + R) >> 1;
        int s1 = query(node * 2 + 1, L, mid, l, r);
        int s2 = query(node * 2 + 2, mid + 1, R, l, r);

        return s1 + s2;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);

        cin >> t;
        int C = 0;
        while (t--)
        {
                int a, b, c;
                cin >> a >> b >> c;
                b += C;
                c += C;
                if (a == 1)
                {
                        int ans = query(0, 1, N, b, c);
                        C = ans;
                        cout << ans << "\n";
                }
                else
                {
                        update(0, 1, N, b, c);
                }
        }

        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 23 ms 1152 KB Output is correct
9 Correct 44 ms 1272 KB Output is correct
10 Correct 42 ms 1528 KB Output is correct
11 Correct 39 ms 1152 KB Output is correct
12 Correct 41 ms 1180 KB Output is correct
13 Incorrect 39 ms 760 KB Output isn't correct
14 Halted 0 ms 0 KB -