답안 #334396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334396 2020-12-09T05:51:34 Z NhoxZuji 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
86 ms 141420 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define fi first
#define se second
#define fr(x, y, z) for (int x = y; x <= z; ++x)
#define loop(x) while(x--)
#define read(x)  freopen(x".INP","r",stdin);
#define write(x) freopen(x".OUT","w",stdout);
#define nametask "f"

using namespace std;
typedef long long ll;

int n, cnt = 1;
struct node{
    int s, l, r, lid, rid, lazy;
    node() : s(0), lid(-1), rid(-1), lazy(0) {}
};
int const maxn = 1e6 + 5;
node st[6 * maxn];

void newleft(int id){
    if (st[id].lid == -1){
        int nod;
        st[id].lid = nod = ++cnt;
        st[nod].l = st[id].l; st[nod].r = (st[id].r + st[id].l) >> 1;
    }
}

void newright(int id){
    if (st[id].rid == -1){
        int nod;
        st[id].rid = nod = ++cnt;
        st[nod].l = ((st[id].r + st[id].l) >> 1) + 1; st[nod].r = st[id].r;
    }
}

void plazy(int id){
    if (st[id].lazy){
        newleft(id); newright(id);
        st[id].s = st[id].r - st[id].l + 1;
        st[st[id].lid].lazy = st[st[id].rid].lazy = 1;
        st[id].lazy = 0;
    }
}

void upd(int id, int l, int r){
    plazy(id);
    if (st[id].l == l && st[id].r == r){
        st[id].lazy = 1;
        plazy(id);
    } else
    {
        newleft(id); newright(id);
        int mid = (st[id].l + st[id].r) >> 1;
        if (l > mid)  upd(st[id].rid, l, r); else
        if (r <= mid) upd(st[id].lid, l, r); else{
            upd(st[id].lid, l, mid);
            upd(st[id].rid, mid + 1, r);
        }

        plazy(st[id].lid); plazy(st[id].rid);
        st[id].s = st[st[id].lid].s + st[st[id].rid].s;
    }
}

int query(int id, int l, int r){
    plazy(id);
    if (st[id].l == l && st[id].r == r) return st[id].s; else
    {
        newleft(id); newright(id);
        int mid = (st[id].l + st[id].r) >> 1;
        if (l > mid)  return query(st[id].rid, l, r); else
        if (r <= mid) return query(st[id].lid, l, r); else
        return query(st[id].lid, l, mid) + query(st[id].rid, mid + 1, r);
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    read(nametask); write(nametask);
    cin >> n;
    st[1].l = 1; st[1].r = (int) 1e9;

    int c = 0;
    for (int i = 1; i <= n; ++i){
        int d, x, y;
        cin >> d >> x >> y;
        if (d == 1){
            c = query(1, x + c, y + c);
            cout << c << "\n";
        } else upd(1, x + c, y + c);
    }
    return 0;
}

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:14:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 | #define read(x)  freopen(x".INP","r",stdin);
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~
apple.cpp:89:5: note: in expansion of macro 'read'
   89 |     read(nametask); write(nametask);
      |     ^~~~
apple.cpp:15:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define write(x) freopen(x".OUT","w",stdout);
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
apple.cpp:89:21: note: in expansion of macro 'write'
   89 |     read(nametask); write(nametask);
      |                     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 141420 KB Output isn't correct
2 Halted 0 ms 0 KB -