답안 #656696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656696 2022-11-08T04:13:25 Z Neos 원숭이와 사과 나무 (IZhO12_apple) C++14
100 / 100
225 ms 71224 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define mid ((l + r) >> 1)

const int N = 1e7 + 7, oo = 1e9;
int n, cnt = 1;
int seg[N], laz[N];
int L[N], R[N];

void gen(int id) {
    if (!L[id]) L[id] = ++cnt;
    if (!R[id]) R[id] = ++cnt;
}
void down(int id, int l, int r) {
    gen(id);
    if (!laz[id]) return;
    seg[L[id]] = laz[L[id]] = mid - l + 1;
    seg[R[id]] = laz[R[id]] = r - mid;
    laz[id] = 0;
}
void upd(int u, int v, int id = 1, int l = 1, int r = oo) {
    if (l > v || r < u) return;
    if (u <= l && r <= v){
        seg[id] = r - l + 1; laz[id] = 1;
        return;
    }
    down(id, l, r);
    upd(u, v, L[id], l, mid);
    upd(u, v, R[id], mid + 1, r);
    seg[id] = seg[L[id]] + seg[R[id]];
}
int get(int u, int v, int id = 1, int l = 1, int r = oo) {
    if (l > v || r < u) return 0;
    if (u <= l && r <= v) return seg[id];
    down(id, l, r);
    return get(u, v, L[id], l, mid) + get(u, v, R[id], mid + 1, r);
}
int main() {
    scanf("%d", &n); int c = 0;
    for (int i = 1, t, l, r; i <= n; i++) {
        scanf("%d %d %d", &t, &l, &r);
        if (t == 1) printf("%d\n", (c = get(c + l, c + r)));
        else upd(c + l, c + r);
    }
}

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &n); int c = 0;
      |     ~~~~~^~~~~~~~~~
apple.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%d %d %d", &t, &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 2004 KB Output is correct
5 Correct 11 ms 2352 KB Output is correct
6 Correct 12 ms 2312 KB Output is correct
7 Correct 12 ms 2260 KB Output is correct
8 Correct 76 ms 15664 KB Output is correct
9 Correct 161 ms 27412 KB Output is correct
10 Correct 165 ms 30064 KB Output is correct
11 Correct 173 ms 32200 KB Output is correct
12 Correct 169 ms 33096 KB Output is correct
13 Correct 151 ms 38484 KB Output is correct
14 Correct 153 ms 38900 KB Output is correct
15 Correct 216 ms 69180 KB Output is correct
16 Correct 216 ms 69728 KB Output is correct
17 Correct 164 ms 40216 KB Output is correct
18 Correct 154 ms 40144 KB Output is correct
19 Correct 219 ms 71224 KB Output is correct
20 Correct 225 ms 71180 KB Output is correct