답안 #1086279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086279 2024-09-10T01:29:07 Z Flan312 원숭이와 사과 나무 (IZhO12_apple) C++17
100 / 100
260 ms 139628 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
using namespace std;
struct node
{
    int cnt;
    bool lazy;
    node *l, *r;
    node(int cnt = 0, bool lazy = 0) : cnt(cnt), lazy(lazy)
    {
        l = r = nullptr;
    }
};
#define check(x) if (x == nullptr) x = new node();

void assign(node *root, int l, int r, int val)
{
    if (!val) return;
    root -> cnt = r - l + 1;
    root -> lazy = 1;
}

void down(node *root, int l, int r)
{
    check(root -> l);
    check(root -> r);
    if (!root -> lazy) return;
    int mid = l + r >> 1;
    assign(root -> l, l, mid, root -> lazy);
    assign(root -> r, mid + 1, r, root -> lazy);
    root -> lazy = 0;
}
void update(node *root, int l, int r, int u, int v)
{
    if (l > v || r < u) return;
    if (l >= u && r <= v)
        return assign(root, l, r, v);
    down(root, l, r);
    int mid = l + r >> 1;
    if (u <= mid) update(root -> l, l, mid, u, v);
    if (mid < v) update(root -> r, mid + 1, r, u, v);
    root -> cnt = (root -> l -> cnt) + (root -> r -> cnt);
}
int query(node *root, int l, int r, int u, int v)
{
    if (root == nullptr) return 0;
    if (l > v || r < u) return 0;
    if (l >= u && r <= v) 
        return root -> cnt;
    down(root, l, r);
    int mid = l + r >> 1;
    int res = 0;
    if (u <= mid) res += query(root -> l, l, mid, u, v);
    if (mid < v) res += query(root -> r, mid + 1, r, u, v);
    return res;
}
node *root = new node();
int t;
int main()
{
    if (ifstream(task".inp")) nx
    fast
    cin >> t;
    int c = 0;
    while(t--)
    {
        int type, l, r;
        cin >> type >> l >> r;
        l += c, r += c;
        if (type == 1)
        {
            c = query(root, 1, 1e9, l, r);
            cout << c << '\n';
        }
        else update(root, 1, 1e9, l, r);
    }
}

Compilation message

apple.cpp: In function 'void down(node*, int, int)':
apple.cpp:37:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In function 'void update(node*, int, int, int, int)':
apple.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In function 'int query(node*, int, int, int, int)':
apple.cpp:60:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In function 'int main()':
apple.cpp:7:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:70:31: note: in expansion of macro 'nx'
   70 |     if (ifstream(task".inp")) nx
      |                               ^~
apple.cpp:7:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |                                            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:70:31: note: in expansion of macro 'nx'
   70 |     if (ifstream(task".inp")) nx
      |                               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 8 ms 3420 KB Output is correct
5 Correct 10 ms 4188 KB Output is correct
6 Correct 11 ms 4188 KB Output is correct
7 Correct 10 ms 4304 KB Output is correct
8 Correct 79 ms 30204 KB Output is correct
9 Correct 152 ms 52308 KB Output is correct
10 Correct 155 ms 57824 KB Output is correct
11 Correct 161 ms 61904 KB Output is correct
12 Correct 194 ms 63824 KB Output is correct
13 Correct 153 ms 74324 KB Output is correct
14 Correct 164 ms 75092 KB Output is correct
15 Correct 260 ms 135480 KB Output is correct
16 Correct 246 ms 136532 KB Output is correct
17 Correct 161 ms 77652 KB Output is correct
18 Correct 168 ms 77656 KB Output is correct
19 Correct 252 ms 139600 KB Output is correct
20 Correct 243 ms 139628 KB Output is correct