Submission #656694

# Submission time Handle Problem Language Result Execution time Memory
656694 2022-11-08T04:10:32 Z Neos Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
0 ms 340 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;
ll 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) {
    if (!laz[id]) return;
    gen(id);
    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); gen(id);
    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) {
            int ans = get(c + l, c + r); c += ans;
            printf("%d\n", ans);
        }
        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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -