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

推荐订阅源

Forbes - Security
Forbes - Security
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
P
Proofpoint News Feed
P
Privacy International News Feed
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
S
Securelist
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
GbyAI
GbyAI
B
Blog RSS Feed
A
About on SuperTechFans
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyberwarzone
Cyberwarzone
I
Intezer
T
Tor Project blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
D
DataBreaches.Net
U
Unit 42
Project Zero
Project Zero
Martin Fowler
Martin Fowler
V
V2EX
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V2EX - 技术
V2EX - 技术
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tenable Blog
F
Full Disclosure
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
Latest news
Latest news
Webroot Blog
Webroot Blog

博客园 - 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 }