比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAAWWW
题目名称 Asm.Def的命令 最终得分 70
用户昵称 subaru 运行时间 0.347 s
代码语言 C++ 内存使用 22.81 MiB
提交时间 2019-10-23 17:39:14
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

inline int read() {
    int op = 1, a = 0; char c = getchar();
    for (; c < '0' || c > '9'; c = getchar()) if (c == '-') op = -1;
    for (; c >= '0' && c <= '9'; c = getchar()) a = a * 10 + c - '0';
    return op * a;
}

const int maxn = 1e5 + 5;
int n, q;

#define lc (u << 1)
#define rc (u << 1 | 1)
struct Seg {
    int l, r, x, y, xtag, ytag;
    inline void init(int tmp) { l = r = tmp; x = 0, y = tmp, xtag = ytag = 0; }
    Seg operator + (const Seg& rhs) const {
        Seg u; u.l = l, u.r = rhs.r;
        u.xtag = 0; u.ytag = 0; return u;
    }
} tr[maxn << 2];

inline void pushdown(int u) {
    if (tr[u].xtag) {
        tr[lc].xtag += tr[u].xtag, tr[rc].xtag += tr[u].xtag;
        if (tr[lc].l == tr[lc].r) tr[lc].x += tr[u].xtag;
        if (tr[rc].l == tr[rc].r) tr[rc].x += tr[u].xtag;
        tr[u].xtag = 0;
    }
    if (tr[u].ytag) {
        tr[lc].ytag += tr[u].ytag, tr[rc].ytag += tr[u].ytag;
        if (tr[lc].l == tr[lc].r) tr[lc].y += tr[u].ytag;
        if (tr[rc].l == tr[rc].r) tr[rc].y += tr[u].ytag;
        tr[u].ytag = 0;
    }
}

inline void color(int u, int x, int y) {
    tr[u].xtag += x, tr[u].ytag += y;
    if (tr[u].l == tr[u].r) { tr[u].x += x, tr[u].y += y; }
}

void build(int u, int l, int r) {
    if (l == r) { tr[u].init(l); return; }
    int mid = (l + r) >> 1;
    build(lc, l, mid), build(rc, mid + 1, r);
    tr[u] = tr[lc] + tr[rc];
}

void modify(int u, int l, int r, int x, int y) {
    if (l <= tr[u].l && r >= tr[u].r) { color(u, x, y); return; }
    pushdown(u);
    int mid = (tr[u].l + tr[u].r) >> 1;
    if (l <= mid) modify(lc, l, r, x, y);
    if (r > mid) modify(rc, l, r, x, y);
}

Seg query(int u, int l) {
    if (tr[u].l == tr[u].r) return tr[u];
    pushdown(u);
    int mid = (tr[u].l + tr[u].r) >> 1;
    if (l <= mid) return query(lc, l);
    else return query(rc, l);
}

int main() {
    freopen("asm_command.in", "r", stdin);
    freopen("asm_command.out", "w", stdout);
    n = read(), q = read();
    build(1, 1, n);
    for (; q; q--) {
        int opt = read(), l, r, x, y, deg;
        if (opt == 0) {
            l = read();
            Seg ans = query(1, l);
            cout << ans.x << ".0" << ' ' << ans.y << ".0" << '\n';
        }
        else if (opt == 1) {
            l = read(), r = read(), x = read(), y = read();
            modify(1, l, r, x, y);
        }
    }
    return 0;
}