\(\text{Solution}\)

明显的 \(\text{K-D Tree}\) 基操题

提前给出了数列,那么考虑提前建好树,省去重构

但还是要开 \(O\)

\(\text{Code}\)

#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC diagnostic error "-std=c++14"
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC optimize("fast-math","unroll-loops","no-stack-protector","inline")
#include <cstdio>
#include <iostream>
#include <algorithm>
#define LL long long
#define re register
using namespace std; const int N = 5e4 + 5;
const LL P = 536870912;
int n, m, cur, x0, y0, x1, y1, rt, L1[N], L2[N], R1[N], R2[N], siz[N], ls[N], rs[N], ds[N], gs[N];
LL sum[N], tg1[N], tg2[N], v1, v2;
struct node{int x, y; LL v;}s[N];
inline bool cmpx(int a, int b){return s[a].x < s[b].x;}
inline bool cmpy(int a, int b){return s[a].y < s[b].y;} inline void read(int &x)
{
x = 0; char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
} inline void update(int p, int o)
{
L1[p] = min(L1[p], L1[o]), R1[p] = max(R1[p], R1[o]);
L2[p] = min(L2[p], L2[o]), R2[p] = max(R2[p], R2[o]);
}
inline void maintain(int p)
{
siz[p] = siz[ls[p]] + siz[rs[p]] + 1, sum[p] = sum[ls[p]] + sum[rs[p]] + s[p].v;
L1[p] = R1[p] = s[p].x, L2[p] = R2[p] = s[p].y;
if (ls[p]) update(p, ls[p]); if (rs[p]) update(p, rs[p]);
} int build(int l, int r)
{
if (l > r) return 0;
int mid = (l + r) >> 1;
double av1 = 0, av2 = 0, s1 = 0, s2 = 0;
for(re int i = l; i <= r; i++) av1 += s[gs[i]].x, av2 += s[gs[i]].y;
av1 /= (r - l + 1), av2 /= (r - l + 1);
for(re int i = l; i <= r; i++)
s1 += (av1 - s[gs[i]].x) * (av1 - s[gs[i]].x), s2 += (av2 - s[gs[i]].y) * (av2 - s[gs[i]].y);
if (s1 > s2) nth_element(gs + l, gs + mid, gs + r + 1, cmpx), ds[gs[mid]] = 1;
else nth_element(gs + l, gs + mid, gs + r + 1, cmpy), ds[gs[mid]] = 2;
ls[gs[mid]] = build(l, mid - 1), rs[gs[mid]] = build(mid + 1, r), maintain(gs[mid]);
return gs[mid];
} inline void add1(int p, LL v)
{
s[p].v = s[p].v * v % P, sum[p] = sum[p] * v % P, tg1[p] = tg1[p] * v % P, tg2[p] = tg2[p] * v % P;
}
inline void add2(int p, LL v)
{
s[p].v = (s[p].v + v) % P, sum[p] = (sum[p] + v * siz[p] % P) % P, tg2[p] = (tg2[p] + v) % P;
}
inline void pushdown(int p)
{
add1(ls[p], tg1[p]), add1(rs[p], tg1[p]), tg1[p] = 1;
if (tg2[p]) add2(ls[p], tg2[p]), add2(rs[p], tg2[p]), tg2[p] = 0;
} void modify(int p)
{
if (!p || L1[p] > x1 || R1[p] < x0 || L2[p] > y1 || R2[p] < y0) return;
if (x0 <= L1[p] && R1[p] <= x1 && y0 <= L2[p] && R2[p] <= y1) return add1(p, v1), add2(p, v2);
if (s[p].x >= x0 && s[p].x <= x1 && s[p].y >= y0 && s[p].y <= y1)
sum[p] = (sum[p] - s[p].v + P) % P, s[p].v = (s[p].v * v1 % P + v2) % P, sum[p] = (sum[p] + s[p].v) % P;
pushdown(p), modify(ls[p]), modify(rs[p]), maintain(p);
} LL query(int p)
{
if (!p || L1[p] > x1 || R1[p] < x0 || L2[p] > y1 || R2[p] < y0) return 0;
if (x0 <= L1[p] && R1[p] <= x1 && y0 <= L2[p] && R2[p] <= y1) return sum[p];
pushdown(p);
LL res = 0;
if (s[p].x >= x0 && s[p].x <= x1 && s[p].y >= y0 && s[p].y <= y1) res = s[p].v;
return (res + query(ls[p]) + query(rs[p])) % P;
} int main()
{
freopen("sequence.in", "r", stdin), freopen("sequence.out", "w", stdout);
read(n), read(m);
for(re int i = 1; i <= n; i++) ++cur, read(s[cur].y), s[cur].x = i, gs[++gs[0]] = i, tg1[i] = 1;
rt = build(1, n);
for(int opt; m; m--)
{
read(opt);
if (opt == 0) read(x0), read(x1), read(y0), read(y1), v1 = y0, v2 = y1, y0 = 1, y1 = n, modify(rt);
else if (opt == 1) read(y0), read(y1), read(x0), read(x1), v1 = x0, v2 = x1, x0 = 1, x1 = n, modify(rt);
else if (opt == 2) read(x0), read(x1), y0 = 1, y1 = n, printf("%lld\n", query(rt));
else if (opt == 3) read(y0), read(y1), x0 = 1, x1 = n, printf("%lld\n", query(rt));
}
}

JZOJ 3469. 【NOIP2013模拟联考7】数列(sequence)的更多相关文章

  1. JZOJ【NOIP2013模拟联考14】隐藏指令

    JZOJ[NOIP2013模拟联考14]隐藏指令 题目 Description 在d维欧几里得空间中,指令是一个长度为2N的串.串的每一个元素为d个正交基的方向及反方向之一.例如,d = 1时(数轴) ...

  2. JZOJ 3462. 【NOIP2013模拟联考5】休息(rest)

    3462. [NOIP2013模拟联考5]休息(rest) (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed ...

  3. JZOJ 3461. 【NOIP2013模拟联考5】小麦亩产一千八(kela)

    3461. [NOIP2013模拟联考5]小麦亩产一千八(kela) (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB  Det ...

  4. JZOJ 3493. 【NOIP2013模拟联考13】三角形

    3493. [NOIP2013模拟联考13]三角形(triangle) (File IO): input:triangle.in output:triangle.out Time Limits: 10 ...

  5. JZOJ 3487. 【NOIP2013模拟联考11】剑与魔法(dragons)

    3487. [NOIP2013模拟联考11]剑与魔法(dragons) (Standard IO) Time Limits: 1000 ms  Memory Limits: 131072 KB  De ...

  6. JZOJ 3470. 【NOIP2013模拟联考8】最短路(path)

    470. [NOIP2013模拟联考8]最短路(path) (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed ...

  7. JZOJ 3463. 【NOIP2013模拟联考5】军训

    3463. [NOIP2013模拟联考5]军训(training) (Standard IO) Time Limits: 2000 ms  Memory Limits: 262144 KB  Deta ...

  8. 【NOIP2013模拟联考7】OSU

    [NOIP2013模拟联考7]OSU 描述 Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分, ...

  9. [jzoj]3468.【NOIP2013模拟联考7】OSU!(osu)

    Link https://jzoj.net/senior/#main/show/3468 Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: ...

  10. [jzoj]3456.【NOIP2013模拟联考3】恭介的法则(rule)

    Link https://jzoj.net/senior/#main/show/3456 Description 终于,在众亲们的奋斗下,最终boss 恭介被关进了库特设计的密室.正当她们松了一口气时 ...

随机推荐

  1. 关于js更改编码问题

    前言 前几天调试喜马拉雅的js加密算法,找到固定一段加密算法后调试,发现结果与实际不一致,后来发现是js显示的编码不一致,而我用的密钥是直接通过 chrome控制台复制下来的,这就导致最后结果不一致. ...

  2. postman的运用

    链接: https://pan.baidu.com/s/1gfaKoAv 密码: dp7t 最近要测试和其他系统对接,忽然想起了postman这款url测试神器. 现分享如下: 下载完成后解压到文件夹 ...

  3. 这可能是最全的SpringBoot3新版本变化了!

    11月24号,Spring Boot 3.0 发布了第一个正式的 GA 版本,一起看看新版本到底有哪些变化. 2.7版本升级指南 官方提供了一个从 2.7 版本升级到 3.0 的指南:https:// ...

  4. Linux 基础-新手必备命令

    Linux 基础-新手必备命令 概述 常见执行 Linux 命令的格式是这样的: 命令名称 [命令参数] [命令对象] 注意,命令名称.命令参数.命令对象之间请用空格键分隔. 命令对象一般是指要处理的 ...

  5. 用最少的代码打造一个Mini版的gRPC框架

    在<用最少的代码模拟gRPC四种消息交换模式>中,我使用很简单的代码模拟了gRPC四种消息交换模式(Unary.Client Streaming.Server Streaming和Dupl ...

  6. 8、ThreadPoolTaskExecutor线程并发

    一.线程池的优点: 1.降低资源消耗.通过重复利用自己创建的线程降低线程创建和销毁造成的消耗. 2.提高响应速度.当任务到达时,任务可以不需要等到线程创建就能立即执行. 3.提高线程的可管理性.线程是 ...

  7. P3Depth: Monocular Depth Estimation with a Piecewise Planarity Prior

    1. 论文简介 论文题目:P3Depth: Monocular Depth Estimation with a Piecewise Planarity Prior Paper地址:paper Code ...

  8. [python] 基于Gradio可视化部署机器学习应用

    Gradio是一个开源的Python库,用于构建机器学习和数据科学演示应用.有了Gradio,你可以围绕你的机器学习模型或数据科学工作流程快速创建一个简单漂亮的用户界面.Gradio适用于以下情况: ...

  9. BalticOI 2004 Sequence 题解

    题目链接在这里~ 对于序列\(\{a\}\),把每一个\(a_i\)减去一个\(i\),得到\(\{a'\}\)序列\(\{b\}\)同理. 因为\(b_1<b_2<...<b_n\ ...

  10. MongoDB - 分片简介

    简介 什么是分片 高数据量和高吞吐量的数据库应用会对单机的性能造成较大压力,大的查询会将单机的 CPU 耗尽,大的数据量对单机的存储压力较大,最终会耗尽系统的内存压力转移到磁盘 IO 上. 为了解决这 ...