Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
98690 Ghost_Chris Old Driver Tree C++ 运行出错 0 4 MS 1024 KB 1914 2023-08-16 12:39:04

Tests(0/4):


#include <bits/stdc++.h> #define ll long long using namespace std; inline ll read() { register ll x(0); register int w(1); register char c(getchar()); for (; c < '0' || c > '9'; c = getchar()) if (c == '-') w = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * w; } const int N(1e5 + 10); ll a[N], n; ll len[N << 2], t[N << 2]; inline int ls(int x) { return x << 1; } inline int rs(int x) { return x << 1 | 1; } void push_up(int x) { t[x] = (t[ls(x)] == t[rs(x)] ? t[ls(x)] : -1); return ; } void build(int x, int l, int r) { len[x] = r - l + 1; if (l == r) { t[x] = a[l]; return; } int mid(l + r >> 1); build(ls(x), l, mid); build(rs(x), mid + 1, r); push_up(x); return ; } void push_down(int x) { if (len[x] == 1) return; if (t[x] != -1) t[ls(x)] = t[rs(x)] = t[x]; return ; } ll ask(int x, int l, int r, int L, int R, ll c) { if (t[x] == c) return min(r, R) - max(l, L) + 1; push_down(x); int mid(l + r >> 1); ll res(0); if (l >= L && r <= R) { if (t[x] != -1 && t[x] != c) { t[x] = c; return 0; } res = ask(ls(x), l, mid, L, R, c) + ask(rs(x), mid + 1, r, L, R, c); push_up(x); return res; } if (L <= mid) res = ask(ls(x), l, mid, L, R, c); if (R >= mid + 1) res += ask(rs(x), mid + 1, r, L, R, c); push_up(x); return res; } int main() { n = read(); for (int i(1); i <= n; i++) a[i] = read(); build(1, 1, n); for (; n--;) { ll l(read()), r(read()), c(read()); cout << ask(1, 1, n, l, r, c) << endl; } return 0; }


测评信息: