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

using namespace std;

const int maxn = 1e5 + 5;

struct Node {
    int l, r;
    double xval, yval, xlazy, ylazy;
}a[maxn << 2 | 1];

int n, m;
int opt, fr, to, haj, xsy;

int read(void)
{
    int s = 0, w = 1;
    char ch = getchar();
    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1;
    for(; ch <= '9' && ch >= '0'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}

void build(int u, int l, int r)
{
    a[u].l = l;
    a[u].r = r;
    if(l == r)
    {
        a[u].yval = l;
        return ;
    }
    int mid = (a[u].l + a[u].r) >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
}

inline void getvis(int u, double xdelta, double ydelta)
{
    a[u].xval += xdelta;
    a[u].yval += ydelta;
    a[u].xlazy += xdelta;
    a[u].ylazy += ydelta;
}

inline void push_down(int u)
{
    if(a[u].xlazy)
    {
        getvis(u << 1, a[u].xlazy, 0);
        getvis(u << 1 | 1, a[u].xlazy, 0);
        a[u].xlazy = 0;
    }

    if(a[u].ylazy)
    {
        getvis(u << 1, 0, a[u].ylazy);
        getvis(u << 1 | 1, 0, a[u].ylazy);
        a[u].ylazy = 0;
    }
}

void change(int u, int l, int r, double xdelta, double ydelta)
{
    if(a[u].l == l && a[u].r == r)
    {
        getvis(u, xdelta, ydelta);
        return ;
    }
    push_down(u);
    int mid = (a[u].l + a[u].r) >> 1;
    if(r <= mid) change(u << 1, l, r, xdelta, ydelta);
    else if(l > mid) change(u << 1 | 1, l, r, xdelta, ydelta);
    else {
        change(u << 1, l, mid, xdelta, ydelta);
        change(u << 1 | 1, mid + 1, r, xdelta, ydelta);
    }
}

pair<double, double> query(int u, int pos)
{
    if(a[u].l == a[u].r) return make_pair(a[u].xval, a[u].yval);
    push_down(u);
    int mid = (a[u].l + a[u].r) >> 1;
    if(pos <= mid) return query(u << 1, pos);
    else return query(u << 1 | 1, pos);
}

int main()
{
    freopen("asm_command.in", "r", stdin);
    freopen("asm_command.out", "w", stdout);
    cin >> n >> m;
    build(1, 1, n);
    for(int i = 1; i <= m; i++)
    {
        cin >> opt;
        if(opt == 0)
        {
            cin >> fr;
            pair<double, double> A = query(1, fr);
            cout << setprecision(1) << fixed << A.first << ' ' << setprecision(1) << fixed << A.second << '\n';
        }
        else if(opt == 1)
        {
            cin >> fr >> to >> haj >> xsy;
            change(1, fr, to, haj, xsy);
        }
    }
    return 0;
}