比赛 |
Asm.Def战记之圣地亚哥“杯2015 |
评测结果 |
AAAAAAAWWW |
题目名称 |
Asm.Def的命令 |
最终得分 |
70 |
用户昵称 |
CoolBoy小逴 |
运行时间 |
0.536 s |
代码语言 |
C++ |
内存使用 |
23.58 MiB |
提交时间 |
2019-10-23 18:02:52 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define Re register
#define lson rt << 1
#define rson rt << 1 | 1
using namespace std;
const int maxn = 1e5 + 10;
int n, q, op;
int a, b, dx, dy, deg, X, Y;
struct node{
int x, y;
}c[maxn];
struct SegmentTree{
int l, r;
int x, y;
int tagx, tagy;
}z[maxn << 2];
int f_;
char ch_;
template <class T>
inline T read (T &x_){
x_ = 0, f_ = 1, ch_ = getchar();
while (ch_ > '9' || ch_ < '0'){if (ch_ == '-') f_ = -1; ch_ = getchar();}
while (ch_ >= '0' && ch_ <= '9') x_ = (x_ << 3) + (x_ << 1) + ch_ - 48, ch_ = getchar();
return x_ *= f_;
}
void update (int rt){
z[rt].x = (z[lson].x + z[rson].x);
z[rt].y = (z[lson].y + z[rson].y);
return;
}
void build (int rt, int l, int r){
z[rt].l = l;
z[rt].r = r;
if (l == r){
z[rt].y = c[l].y;
return;
}
Re int mid = (l + r) >> 1;
build (lson, l, mid);
build (rson, mid+1, r);
update(rt);
}
void spread(int rt){
if (z[rt].tagx){
z[lson].x += (z[lson].r - z[lson].l + 1) * z[rt].tagx;
z[rson].x += (z[rson].r - z[rson].l + 1) * z[rt].tagx;
z[lson].tagx += z[rt].tagx;
z[rson].tagx += z[rt].tagx;
z[rt].tagx = 0;
}
if (z[rt].tagy){
z[lson].y += (z[lson].r - z[lson].l + 1) * z[rt].tagy;
z[rson].y += (z[rson].r - z[rson].l + 1) * z[rt].tagy;
z[lson].tagy += z[rt].tagy;
z[rson].tagy += z[rt].tagy;
z[rt].tagy = 0;
}
}
void modify (int rt, int l, int r, int x, int y){
if (l <= z[rt].l && r >= z[rt].r){
z[rt].x += (z[rt].r - z[rt].l + 1) * x;
z[rt].tagx += x;
z[rt].y += (z[rt].r - z[rt].l + 1) * y;
z[rt].tagy += y;
return;
}
spread(rt);
Re int mid = (z[rt].l + z[rt].r) >> 1;
if (l <= mid) modify (lson, l, r, x, y);
if (r > mid) modify (rson, l, r, x, y);
update(rt);
}
void Query (int rt, int x){
if (z[rt].l == z[rt].r) {
X = z[rt].x;
Y = z[rt].y;
return;
}
spread(rt);
Re int mid = (z[rt].l + z[rt].r) >> 1;
if (x <= mid) Query (lson, x);
else Query (rson, x);
}
int main(){
freopen ("asm_command.in", "r", stdin);
freopen ("asm_command.out", "w", stdout);
read(n);
read(q);
for (Re int i = 1;i <= n; ++i) c[i].y = i;
build (1, 1, n);
for (; q; --q){
read(op);
if (!op){
read(a);
Query(1, a);
printf ("%d.0 ", X);
printf ("%d.0\n", Y);
}
if (op == 1){
read(a); read(b);
read(dx); read(dy);
modify (1, a, b, dx, dy);
}
if (op == 2){
read(a); read(b); read(deg);
}
}
return 0;
}