P1967 [NOIP2013 提高组] 货车运输 做题记录
套路题了。
根据和角公式 \(\mathrm{\sin (\alpha + \beta) = \sin \alpha \cos \beta + \cos \alpha \cos \beta, \cos (\alpha + \beta) = \cos \alpha \cos \beta - \sin \alpha \sin \beta}\)
可以考虑在复平面上维护一个复数 \(\mathrm{\sin \alpha + \cos \alpha i}\),或者矩阵维护。
求和及修改可以线段树。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define rep(i, a, b) for (int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (int i = (a); i < (b); i ++ )
#define dep(i, a, b) for (int i = (a); i >= (b); i -- )
#define dop(i, a, b) for (int i = (a); i > (b); i -- )
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int N = 300010;
const double pi = acos(-1);
const double eps = 1e-6;
int n, m;
double w[N];
struct Complex {
double x, y;
Complex(){}
Complex(double _x, double _y) { x = _x, y = _y; }
Complex operator + (const Complex& tmp)const {
return Complex(x + tmp.x, y + tmp.y);
}
Complex operator * (const Complex& tmp)const {
return Complex(x * tmp.x - y * tmp.y, x * tmp.y + y * tmp.x);
}
Complex operator - (const Complex& tmp)const {
return Complex(x - tmp.x, y - tmp.y);
}
Complex operator * (const double &tmp)const {
return Complex(x * tmp, y * tmp);
}
void clear() { x = y = 0; }
void makeI() { x = 1.0, y = 0; }
bool empty() { return x == 0 && y == 0; }
bool isI() { return x == 1 && y == 0; }
};
struct Tree {
int l, r;
Complex mul, sum;
int len() { return r - l + 1; }
}tr[N << 2];
#define ls u << 1
#define rs u << 1 | 1
void pushup(int u) {
tr[u].sum = tr[ls].sum + tr[rs].sum;
}
void push_mul(int u, Complex mul) {
if (tr[u].l == tr[u].r) {
tr[u].sum = tr[u].sum * mul;
return;
}
tr[u].mul = tr[u].mul * mul;
tr[u].sum = tr[u].sum * mul;
}
void pushdown(int u) {
if (tr[u].l == tr[u].r) return;
if (!tr[u].mul.isI()) {
push_mul(ls, tr[u].mul);
push_mul(rs, tr[u].mul);
tr[u].mul.makeI();
}
}
void build(int u, int l, int r) {
tr[u] = {l, r}, tr[u].mul.makeI();
if (l == r) {
tr[u].sum = Complex(sin(w[r]), cos(w[r]));
return;
}
int mid = l + r >> 1;
build(ls, l, mid), build(rs, mid + 1, r);
pushup(u);
}
void Multiply(int u, int l, int r, Complex k) {
if (tr[u].l >= l && tr[u].r <= r) {
push_mul(u, k); return;
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid) Multiply(ls, l, r, k);
if (r > mid) Multiply(rs, l, r, k);
pushup(u);
}
Complex query(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) return tr[u].sum;
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1; Complex ans(0, 0);
if (l <= mid) ans = ans + query(ls, l, r);
if (r > mid) ans = ans + query(rs, l, r);
return ans;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i ++ )
scanf("%lf", &w[i]);
build(1, 1, n);
scanf("%d", &m);
while (m -- ) {
int op, l, r; double v;
scanf("%d%d%d", &op, &l, &r);
if (op == 1) {
scanf("%lf", &v);
Multiply(1, l, r, Complex(cos(v), -sin(v)));
}
else
printf("%.1lf\n", query(1, l, r).x);
}
return 0;
}
P1967 [NOIP2013 提高组] 货车运输 做题记录的更多相关文章
- [NOIP2013提高组]货车运输
题目:洛谷P1967.Vijos P1843.codevs3287. 题目大意:有n个城市m条道路,每条道路有一个限重,规定货车运货不能超过限重.有一些询问,问你两个城市之间一次最多能运多少重的货(可 ...
- [NOIP2013 提高组] 货车运输
前言 使用算法:堆优化 \(prim\) , \(LCA\) . 题意 共有 \(n\) 个点,有 \(m\) 条边来连接这些点,每条边有权值.有 \(q\) 条类似于 \(u\) \(v\) 询问, ...
- 洛谷P1967 [NOIP2013提高组Day1T2]货车运输
P1967 货车运输 题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过 ...
- [NOIp2013提高组]积木大赛/[NOIp2018提高组]铺设道路
[NOIp2013提高组]积木大赛/[NOIp2018提高组]铺设道路 题目大意: 对于长度为\(n(n\le10^5)\)的非负数列\(A\),每次可以选取一个区间\(-1\).问将数列清零至少需要 ...
- [NOIP2013 提高组] 华容道 P1979 洛谷
[NOIP2013 提高组] 华容道 P1979 洛谷 强烈推荐,更好的阅读体验 经典题目:spfa+bfs+转化 题目大意: 给出一个01网格图,和点坐标x,y空格坐标a,b,目标位置tx,ty要求 ...
- UOJ 做题记录
UOJ 做题记录 其实我这么弱> >根本不会做题呢> > #21. [UR #1]缩进优化 其实想想还是一道非常丝播的题目呢> > 直接对于每个缩进长度统计一遍就好 ...
- project euler做题记录
ProjectEuler_做题记录 简单记录一下. problem 441 The inverse summation of coprime couples 神仙题.考虑答案为: \[\begin{a ...
- Sam做题记录
Sam做题记录 Hihocoder 后缀自动机二·重复旋律5 求一个串中本质不同的子串数 显然,答案是 \(\sum len[i]-len[fa[i]]\) Hihocoder 后缀自动机三·重复旋律 ...
- 退役IV次后做题记录
退役IV次后做题记录 我啥都不会了.... AGC023 D 如果所有的楼房都在\(S\)同一边可以直接得出答案. 否则考虑最左最右两边的票数,如果左边>=右边,那么最右边会投给左边,因为就算车 ...
- 退役III次后做题记录(扯淡)
退役III次后做题记录(扯淡) CF607E Cross Sum 计算几何屎题 直接二分一下,算出每条线的位置然后算 注意相对位置这个不能先搞出坐标,直接算角度就行了,不然会卡精度/px flag:计 ...
随机推荐
- Docker V24 及 Docker Compose V2 的安装及使用
前言 Docker 是一款流行的开源容器化平台,使用 Docker 可以有效地隔离应用程序和系统环境,使得应用程序在不同的环境中具有相同的行为 Docker Compose 是一个用于定义和管理多个 ...
- ElasticSearch系列——查询、Python使用、Django/Flask集成、集群搭建,数据分片、位置坐标实现附近的人搜索
@ 目录 Elasticsearch之-查询 一 基本查询 1.1 match查询 1.2 term查询 1.3 terms查询 1.4 控制查询的返回数量(分页) 1.5 match_all 查询 ...
- 【Mac2021版Intel芯片下载】 - Intel芯片推荐安装
[Mac2021版Intel芯片下载] - Intel芯片推荐安装 往下拉有安装图文教程一.下载提示1请点击图标进行下载 ●每个软件下方均标注了该软件的用途,请注意查看: ●如果点击无反应,请换一个浏 ...
- 维修道路(repair)
维修道路(repair) 时间限制: 1 Sec 内存限制: 128 MB 题目描述 由于在十多年前道路改建时的突出贡献, Bob 被任命为维修道路的承包商, 他可以任意 选择两条路径去修理. Bo ...
- linux- 挂载本地iso,配置本地yum
------------------------------------ 关于centos8安装vm-tools: workstation部署centos8之后,不需要单独安装vm-tools,系统已 ...
- JDK21的虚拟线程是什么?和平台线程什么关系?
虚拟线程(Virtual Thread)是 JDK 而不是 OS 实现的轻量级线程(Lightweight Process,LWP),由 JVM 调度.许多虚拟线程共享同一个操作系统线程,虚拟线程的数 ...
- 关于Android Stuido2.3和Eclipse4.4
近3年没有做Android开发了,当时用是ECLISPE电脑配置2g,用的还可以. 现在又重新开始做安卓程序,发现大家都用AS了,作为技术人员,也就开始用了. (几年前AS已经发布,不过是0.x版本, ...
- ES6入门(一)
1.let声明的变量只在let命令所在的代码块内有效 2.不存在变量提升,先使用变量,后定义变量,就会报错. 3.let不允许在相同作用域内,重复声明同一个变量.
- 使用 DDPO 在 TRL 中微调 Stable Diffusion 模型
引言 扩散模型 (如 DALL-E 2.Stable Diffusion) 是一类文生图模型,在生成图像 (尤其是有照片级真实感的图像) 方面取得了广泛成功.然而,这些模型生成的图像可能并不总是符合人 ...
- codeforces #864 div2 B
GCD Partition 这道题首先要解决一个问题,要把区间分成几块,可以证明分成两块是更优 首先我们假设把区间分成了m(>= 2)块 b1, b2, b3, ...,bm,则答案是gcd(b ...