답안 #572091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572091 2022-06-03T15:10:51 Z hgmhc 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
469 ms 262144 KB
#include <bits/stdc++.h>
using namespace std; using ii = pair<int,int>; using ll = long long;
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)

struct node {
    ll v, z;
    ll s, e;
    node *l, *r;
    node(ll s, ll e): v(0), z(0), s(s), e(e) {}
    
    void make() {
        if (s == e) return;
        ll m = (s+e)/2;
        if (!l) l = new node(s,m);
        if (!r) r = new node(m+1,e);
    }
    
    void propagate() {
        if (z) {
            v = e-s+1;
            if (s != e)
                l->z = 1, r->z = 1;
            z = 0;
        }
    }
    
    void update(ll a, ll b) {
        make();
        if (a <= s and e <= b) {
            z = 1, propagate();
            return;
        }
        propagate();
        if (b < s or e < a) return;
        l->update(a,b), r->update(a,b);
        v = (l?l->v:0) + (r?r->v:0);
    }
    
    ll query(ll a, ll b) {
        make(), propagate();
        if (a <= s and e <= b) return v;
        if (b < s or e < a) return 0;
        return (l?l->query(a,b):0) + (r?r->query(a,b):0);
    }
};

int m;

int main() {
    node *ds = new node(1,int(1e9));
    ll c = 0;
    scanf("%d", &m); while (m--)
    {
        int d; ll x, y;
        scanf("%d %lld %lld", &d, &x, &y);
        if (d == 1) {
            c = ds->query(x+c,y+c);
            printf("%lld\n", c);
        } else {
            ds->update(x+c,y+c);
        }
    }
}

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     scanf("%d", &m); while (m--)
      |     ~~~~~^~~~~~~~~~
apple.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%d %lld %lld", &d, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 19 ms 11396 KB Output is correct
5 Correct 24 ms 13868 KB Output is correct
6 Correct 24 ms 13308 KB Output is correct
7 Correct 25 ms 13792 KB Output is correct
8 Correct 198 ms 103396 KB Output is correct
9 Correct 395 ms 175900 KB Output is correct
10 Correct 423 ms 197332 KB Output is correct
11 Correct 444 ms 214164 KB Output is correct
12 Correct 469 ms 221392 KB Output is correct
13 Runtime error 415 ms 262144 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -