0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 07:58:52 +00:00

P4939 Agent2

R43674059
This commit is contained in:
Baoshuo Ren 2020-12-13 21:41:13 +08:00 committed by Baoshuo Ren
parent 0c1f8809f2
commit 6c0ef55d37
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -2,78 +2,37 @@
using namespace std; using namespace std;
struct node { int n, m, op, x, y, t[10000005];
int l, r;
int s, d;
node() {} int lowbit(int k) {
node(int _l, int _r) { return k & -k;
l = _l;
r = _r;
s = d = 0;
}
} tr[10000005 << 2];
int n, m, op, x, y, k;
void pushup(int u) {
tr[u].s = tr[u << 1].s + tr[u << 1 | 1].s;
} }
void pushdown(int u) { void add(int x, int v) {
if (!tr[u].d) return; for (int i = x; i <= n + 1; i += lowbit(i)) {
tr[u << 1].d += tr[u].d; t[i] += v;
tr[u << 1].s += (tr[u << 1].r - tr[u << 1].l + 1) * tr[u].d; }
tr[u << 1 | 1].d += tr[u].d;
tr[u << 1 | 1].s += (tr[u << 1 | 1].r - tr[u << 1 | 1].l + 1) * tr[u].d;
tr[u].d = 0;
} }
void build(int u, int l, int r) { int sum(int x) {
tr[u] = node(l, r); int ans = 0;
if (l == r) { for (int i = x; i > 0; i -= lowbit(i)) {
return; ans += t[i];
} }
int mid = l + r >> 1; return ans;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
}
void modify(int u, int l, int r, int d) {
if (tr[u].l >= l && tr[u].r <= r) {
tr[u].d += d;
tr[u].s += (tr[u].r - tr[u].l + 1) * d;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
pushdown(u);
if (l <= mid) modify(u << 1, l, r, d);
if (r > mid) modify(u << 1 | 1, l, r, d);
pushup(u);
}
int query(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) {
return tr[u].s;
}
int mid = tr[u].l + tr[u].r >> 1;
int s = 0;
pushdown(u);
if (l <= mid) s += query(u << 1, l, r);
if (r > mid) s += query(u << 1 | 1, l, r);
return s;
} }
int main() { int main() {
cin >> n >> m; cin >> n >> m;
build(1, 1, n);
for (int i = 0; i < m; i++) { for (int i = 0; i < m; i++) {
cin >> op >> x; cin >> op >> x;
if (op == 0) { if (op == 0) {
cin >> y; cin >> y;
modify(1, x, y, 1); add(x, 1);
add(y + 1, -1);
} }
else if (op == 1) { else if (op == 1) {
cout << query(1, x, x) << endl; cout << sum(x) << endl;
} }
} }
return 0; return 0;