比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAATTT
题目名称 Asm.Def的命令 最终得分 70
用户昵称 liujiaqi 运行时间 9.330 s
代码语言 C++ 内存使用 23.29 MiB
提交时间 2019-10-23 17:44:18
显示代码纯文本
#include <cmath>
#include <cstdio>
#include <algorithm>
#define ls u << 1
#define rs u << 1 | 1
int v, c;
template <class T> T read(T& x) {
	x = 0; v = 1; c = getchar();
	for (; c < '0' || c > '9'; c = getchar()) if (c == '-') v = -1;
	for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x *= v;
}
const int N = 400010;
const double EPS = 1e-6;
int Q, n, opt, x, y, dx, dy;
int L[N], R[N];
struct Segment {
	double sum[N], tag[N];
	inline void update(int u) {
		sum[u] = sum[ls] + sum[rs];
	}
	void build(int u, int l, int r) {
		L[u] = l; R[u] = r;
		if (l == r) {
			sum[u] = l; return;
		}
		int mid = (l + r) >> 1;
		build(ls, l, mid);
		build(rs, mid + 1, r);
		update(u);
	}
	inline void pushTag(int u) {
		if (!tag[u]) return;
		tag[ls] += tag[u]; tag[rs] += tag[u];
		sum[ls] += tag[u] * double(R[ls] - L[ls] + 1);
		sum[rs] += tag[u] * double(R[rs] - L[rs] + 1);
		tag[u] = 0.0;
	}
	void modify(int u, int x, int y, double k) {
		if (x <= L[u] && R[u] <= y) {
			tag[u] += k;
			sum[u] += double(R[u] - L[u] + 1) * k;
			return;
		}
		pushTag(u);
		int mid = (L[u] + R[u]) >> 1;
		if (x <= mid) modify(ls, x, y, k);
		if (y > mid) modify(rs, x, y, k);
		update(u);
	}
	double query(int u, int x) {
		if (L[u] == R[u]) return sum[u];
		pushTag(u);
		int mid = (L[u] + R[u]) >> 1;
		if (x <= mid) return query(ls, x);
		else return query(rs, x);
	}
} tx, ty;
void rotate(int u, int x, int y, double ang) {
	if (L[u] == R[u]) {
		double x1 = tx.sum[u], y1 = ty.sum[u];
		double lean = sqrt(x1 * x1 + y1 * y1);
		double si1 = sin(ang), co1 = cos(ang);
		double si2 = x1 / lean, co2 = y1 / lean;
		double heCos = co1 * co2 - si1 * si2;
		double heSin = si1 * co2 + co1 * si2;
		tx.sum[u] = -heSin * lean;
		ty.sum[u] = -heCos * lean;
		return;
	}
	int mid = (L[u] + R[u]) >> 1;
	if (x <= mid) rotate(ls, x, y, ang);
	if (y > mid) rotate(rs, x, y, ang);
	tx.update(u);
	ty.update(u);
}
void print(double x) {
	if (x < 0 && -x < 1e-6) printf("0.0");
	else printf("%.1lf", x);
}
int main() {
	freopen("asm_command.in", "r", stdin);
	freopen("asm_command.out", "w", stdout);
	read(n); read(Q);
	ty.build(1, 1, n);
	for (; Q; --Q) {
		read(opt); read(x);
		if (!opt) {
			double x1 = tx.query(1, x);
			double x2 = ty.query(1, x);
			print(x1);
			putchar(' ');
			print(x2);
			putchar('\n');
		}
		else if (opt == 1) {
			read(y); read(dx); read(dy);
			tx.modify(1, x, y, dx);
			ty.modify(1, x, y, dy);
		}
		else if (opt == 2) {
			read(y); read(dx);
			double ang = double(dx) * M_PI / 180.0;
			if (dx) rotate(1, x, y, ang);
		}
	}
	return 0;
}