답안 #682917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682917 2023-01-17T08:55:55 Z vjudge1 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
401 ms 262144 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
#define taskname ""

using namespace std;

const long long MAXN = 1e9, INF = 1e18;

struct node
{
    long long left, right;
    long long val = 0;
    bool lazy = false;
    node *left_child = nullptr, *right_child = nullptr;

    node(int lb, int rb)
    {
        left = lb;
        right = rb;
    }

    void extend()
    {
        if (!left_child && left < right)
        {
            int mid = (left + right) / 2;
            left_child = new node(left, mid);
            right_child = new node(mid + 1, right);
        }
    }

    ~node()
    {
        delete left_child;
        delete right_child;
        left_child = NULL;
        right_child = NULL;
    }

    void push()
    {
        if (lazy)
        {
            extend();
            left_child->val = left_child->right - left_child->left + 1;
            left_child->lazy = true;
            right_child->val = right_child->right - right_child->left + 1;
            right_child->lazy = true;
            lazy = false;
        }
    }

    void update(long long l, long long r, long long newval)
    {
        if (l > r)
            return;
        if (l == left && right == r)
        {
            val = right - left + 1;
            lazy = true;
        }
        else
        {
            extend();
            push();
            long long mid = (left + right) / 2;
            left_child->update(l, min(r, mid), newval);
            right_child->update(max(l, mid + 1), r, newval);
            val = left_child->val + right_child->val;
        }
    }

    long long query(long long l, long long r)
    {
        if (l > r)
            return 0;
        if (l == left && r == right)
            return val;
        extend();
        push();
        long long mid = (left + right) / 2;
        return left_child->query(l, min(mid, r)) + right_child->query(max(mid + 1, l), r);
    }
};

void solve()
{
    long long m;
    cin >> m;
    node *root = new node(1, MAXN);
    long long c = 0;
    while (m--)
    {
        long long d, x, y;
        cin >> d >> x >> y;
        if (d == 1)
        {
            c = root->query(x + c, y + c);
            cout << c << '\n';
        }
        else
        {
            root->update(x + c, y + c, 1);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    if (fopen(taskname ".inp", "r"))
    {
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    long long segtree = 1;
    // cin >> segtree;
    while (segtree--)
    {
        solve();
    }
}

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:136:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:137:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 11 ms 6500 KB Output is correct
5 Correct 14 ms 7812 KB Output is correct
6 Correct 17 ms 7636 KB Output is correct
7 Correct 15 ms 7788 KB Output is correct
8 Correct 131 ms 58972 KB Output is correct
9 Correct 237 ms 102292 KB Output is correct
10 Correct 261 ms 113100 KB Output is correct
11 Correct 260 ms 121420 KB Output is correct
12 Correct 276 ms 125280 KB Output is correct
13 Correct 235 ms 145736 KB Output is correct
14 Correct 240 ms 147140 KB Output is correct
15 Runtime error 401 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -