惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
U
Unit 42
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
小众软件
小众软件
V
Visual Studio Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
GbyAI
GbyAI
爱范儿
爱范儿
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
博客园_首页
D
Docker
A
About on SuperTechFans
G
Google Developers Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
V
V2EX
博客园 - Franky

博客园 - zealsoft

洛谷 P2384 最短路题解 洛谷 P2725 邮票题解 洛谷 P2722 总分题解 洛谷 P1219 八皇后题解 洛谷 P2921 在农场万圣节Trick or Treat on the Farm题解 洛谷 P1162 填涂颜色题解 洛谷 P1330 封锁阳光大学题解 洛谷 P1032 字串变换题解 洛谷 P1443 马的遍历题解 洛谷 P1280 尼克的任务题解 洛谷 P1020导弹拦截题解 洛谷 P1141 01迷宫题解 VisualSVNServer无法卸载也无法安装,报告不是有效的MOF文件(0x8004401e)错误 视频捕捉的格式问题 一个VxWorks源代码网站 找个轻量级的Log库还挺难 TAU G2中的BitString和OctetString W32.Downadup.autorun病毒的清除 如何用Visual Studio 2005编译Wireshark的插件
洛谷 P1816 忠诚题解
zealsoft · 2019-09-20 · via 博客园 - zealsoft
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #include <string.h>
 6 #define ll long long
 7 
 8 const int MAXN = 1000001;
 9 
10 using namespace std;
11 
12 ll n, m, a[MAXN], ans[MAXN<<2], tag[MAXN<<2];
13 
14 ll ls(ll x)
15 {
16     return x<<1;
17 }
18 
19 ll rs(ll x)
20 {
21     return x<<1|1;
22 }
23 
24 void push_up(ll p)
25 {
26     ans[p] = min(ans[ls(p)], ans[rs(p)]);
27 }
28 
29 void build(ll p, ll l, ll r)
30 {
31     tag[p] = 0;
32     if(l == r)
33  {
34   ans[p] = a[l];
35   return;
36  }
37     ll mid = (l + r) >> 1;
38     build(ls(p), l, mid);
39     build(rs(p), mid + 1, r);
40     push_up(p);
41 } 
42 
43 void f(ll p, ll l, ll r, ll k)
44 {
45     tag[p] = tag[p] + k;
46     ans[p] = ans[p] + k * (r - l + 1);
47 }
48 
49 void push_down(ll p, ll l, ll r)
50 {
51     ll mid = (l + r)>>1;
52     f(ls(p), l, mid, tag[p]);
53     f(rs(p), mid + 1, r, tag[p]);
54     tag[p] = 0;
55 }
56 
57 ll query(ll q_x, ll q_y, ll l, ll r, ll p)
58 {
59     ll res = 922337203685477580;
60     if(q_x <= l && r <= q_y)
61  {
62   return ans[p];
63  }
64     ll mid = (l + r)>>1;
65     push_down(p, l, r);
66     if(q_x <= mid)
67  {
68   res = min(res, query(q_x, q_y, l, mid, ls(p)));
69  }
70     if(q_y > mid) 
71  {
72   res = min(res, query(q_x, q_y, mid + 1, r, rs(p)));
73  }
74     return res;
75 }
76 
77 int main()
78 {
79      ll e, f;
80     scanf("%lld%lld", &n, &m);
81     for(ll i = 1; i <= n; i++)
82     {
83         scanf("%lld", &a[i]);
84     }
85     build(1, 1, n);
86     for(ll i = 1; i <= m; i++)
87     {
88         scanf("%lld%lld", &e, &f);
89         printf("%lld ", query(e, f, 1, n, 1));
90     }
91     return 0;
92 }