線段樹 洛谷 p1531 I hate it(I hate it too)

這里寫鏈接內容
線段樹模板
字符串是一個很詭異的問題。。。。

#include<cstdio>
#include<iostream>
#include<string>
#define q 200000
using namespace std;
int a[q+5],s[q<<2+5];
void bu(int o,int l,int r)//建樹
{if(l==r){s[o]=a[r];} else{int mid=l+((r-l)>>1);bu(o<<1,l,mid);bu((o<<1)|1,mid+1,r);s[o]=max(s[o<<1],s[(o<<1)|1]);}}
void up(int o,int l,int r,int in,int ans)//修改
{if(l==r){s[o]=ans;return;}int mid=l+((r-l)>>1);if(in<=mid)up(o<<1,l,mid,in,ans);elseup((o<<1)|1,mid+1,r,in,ans);s[o]=max(s[o<<1],s[(o<<1)|1]);}
int qu(int o,int l,int r,int ql,int qr)//查詢輸出
{if(r<ql||l>qr) return -9999;if(ql<=l&&qr>=r){return s[o];}int mid=l+((r-l)>>1);return max(qu(o<<1,l,mid,ql,qr),qu((o<<1)|1,mid+1,r,ql,qr));
}int main(){//freopen("線段樹.in","r",stdin);//freopen("線段樹.out","w",stdout);int n;int m;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) scanf("%d",&a[i]);//getchar();bu(1,1,n+1);for(int i=1;i<=m;i++) {//char b;string b;int c,d;//b=getchar();cin>>b;scanf("%d%d",&c,&d);// getchar();if(b=="Q") {printf("%d\n",qu(1,1,n+1,c,d));    }if(b=="U") {if(a[c]<d){a[c]=d;up(1,1,n+1,c,d);}}}return 0;}

轉載于:https://www.cnblogs.com/wspl98765/p/6819903.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542021.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542021.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542021.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

打開是什么樣子的圖片_情侶頭像 | 無論是什么樣子的你 我都好喜歡

點擊【情侶圖片大全】- 右上角找到【…】立刻設我為星標/置頂 - 不迷路哦情侶圖片大全“時光真瘋狂&#xff0c;我一路執迷與匆忙”情侶/閨蜜/動漫/閨蜜網名長按圖片保存 點擊圖片放大圖片高清&#xff0c;建議在 W i f i 下瀏覽這個世界是多么神奇我竟然遇見了你無論是什么…

Java File類File [] listFiles()方法(帶示例)

File類File [] listFiles() (File Class File[] listFiles()) This method is available in package java.io.File.listFiles(). 軟件包java.io.File.listFiles()中提供了此方法。 This method is used to return the names of all the files in the form of an array of files…

zabbix監控平臺添加服務(http,nginx,mysql)

1 . 監控httpd服務&#xff1a; 首先確保已經搭建zabbix監控平臺&#xff0c;并且將需要監控的主機已經添加。 對主機server2 上的http服務進行監控&#xff0c;首先確保server2主機安裝了http服務。 使用http在zabbix中自帶監控模版 點擊配置->主機->server2->模…

java為什么要重寫hashCode和equals方法

如果不被重寫&#xff08;原生&#xff09;的hashCode和equals是什么樣的&#xff1f;不被重寫&#xff08;原生&#xff09;的hashCode值是根據內存地址換算出來的一個值。 不被重寫&#xff08;原生&#xff09;的equals方法是嚴格判斷一個對象是否相等的方法&#xff0…

stl中map函數_map :: max_size()函數,以及C ++ STL中的Example

stl中map函數C STL映射:: max_size() (C STL map::max_size() ) It returns the maximum number of elements the container(map) is able to hold but at runtime, the size of the container may be limited to a value smaller than specified by max_size() by the amount…

arduino 藍牙示例_Arduino簡單實例之八_藍牙模塊

1) 說明&#xff1a;藍牙模塊用于和手機或其它帶藍牙的設備通訊。藍牙設備分為主從兩種模式&#xff0c;作為主設備時&#xff0c;它查找和連接其它設備&#xff1b;作為從設備時只能被只它設備連接&#xff1b;通訊模式分透明傳輸和AT命令模式。最好購買主從一體的藍牙模…

zabbix使用JMX監控tomcat

JMX 全稱是Java Management Extensions,即Java管理擴展。Java程序會開放一些端口&#xff0c;用來獲取運行狀況。 從Zabbix2.0開始&#xff0c;內置了監控JMX的功能,叫做"Zabbix Java Gateway ",在Zabbix Serve上會啟動名為"Zabbix Java Gateway "的進程&…

自定義控件添加屬性_|AutoCAD LT 2019 Mac自定義功能區的方法

AutoCAD LT是一款非常好用的CAD三維設計繪圖軟件&#xff0c;最新版本2019擁有改進的桌面、新應用實現跨設備工作流&#xff0c;以及DWG比較等新功能&#xff0c;并且AutoCAD LT 2019 Mac可以根據你的需要和工作習慣來自定義功能區&#xff0c;下面為大家帶來自定義功能區的詳細…

操作系統中的文件系統和訪問方法

文件 (File) A file is basically a sequence of bytes organized into blocks that are understandable by any machines. In other words, the collection of related information that is stored in a secondary storage device is also called a file. The file is a colle…

centos7鏡像加速_docker 鏡像加速CentOS7詳細介紹

前言在Docker Hub官網上注冊帳號&#xff0c;即可下載使用倉庫里的全部的docker鏡像。而因為網絡原因&#xff0c;國內的開發者沒辦法流暢的下載鏡像&#xff0c;經常會出現下載中斷的錯誤。解決方法就是使用國內的容器Hub加速服務&#xff0c;本質就是更改pull優先級較高的服務…

java 根據類名示例化類_Java LocalDateTime類| atOffset()方法與示例

java 根據類名示例化類LocalDateTime類atOffset()方法 (LocalDateTime Class atOffset() method) atOffset() method is available in java.time package. atOffset()方法在java.time包中可用。 atOffset() method is used to create an OffsetDateTime to merge this LocalDat…

Zabbix監控——proxy 分布式監控配置

proxy分布式監控 Zabbix proxy是在大規模分布式監控場景中&#xff0c;采用的一種用以分擔server端壓力的分層結構&#xff0c; proxy可以代替zabbix server檢索客戶端的數據&#xff0c;然后把數據匯報給zabbix server&#xff0c;極大的減輕了server的負載壓力&#xff0c;使…

AutoCAD_acadiso.dwt卡死

2019獨角獸企業重金招聘Python工程師標準>>> 問題描述&#xff1a;每次執行到打開acadiso.dwt就卡死&#xff0c;且電腦顯示有網&#xff0c;確打不開網頁 可能原因&#xff1a;可能是因為AotuCAD是盜版的 解決辦法&#xff1a; 1.在任務管理器中把WSCommCntr.exe進…

else 策略模式去掉if_java – 用狀態/策略模式替換if/else邏輯

我認為你應該使用GoF模式Chain of responsibility.你應該引入兩個接口&#xff1a;1)你將檢查正確條件的條件,例如“如果zip文件不存在”并返回布爾結果 – 如果條件滿足則返回“true”,否則“else”,2)執行策略,它將運行分配有條件的動作,例如&#xff1a; “從指定的URL下載它…

docker簡介與搭建

1 . 對docker的理解&#xff1a; Docker 是一個開源的應用容器引擎&#xff0c;讓開發者可以打包他們的應用以及依賴包到一個可移植的鏡像中&#xff0c;然后發布到任何流行的 Linux或Windows 機器上&#xff0c;也可以實現虛擬化。容器是完全使用沙箱機制&#xff0c;相互之間…

Java BigInteger類| toByteArray()方法與示例

BigInteger類testBit()方法 (BigInteger Class testBit() method) testBit() method is available in java.math package. testBit()方法在java.math包中可用。 testBit() method is used to convert this BigInteger to a byte [] that holds 2s complement denotation of thi…

007_Web to lead

轉載于:https://www.cnblogs.com/bandariFang/p/6229491.html

設置header_Nginx的這些安全設置,你都知道嗎?

Nginx 是最流行的 Web 服務器&#xff0c;可以只占用 2.5 MB 的內存&#xff0c;卻可以輕松處理 1w 的 http 請求。做為網站的入口&#xff0c;Nginx 的安全設置重要性不言而喻。下面帶你一起去認識一下這些安全配置吧&#xff01;nginx.conf是 Nginx 最主要的配置文件&#xf…

動態路由協議_動態路由協議的類別

動態路由協議Dynamic routing protocols have been divided into 2 categories i.e Distance vector protocols and Link state protocols. Both of these protocols are being explained in detail in this tutorial. 動態路由協議分為距離矢量協議和鏈路狀態協議兩大類 。 本…

docker鏡像創建與優化

1 . 創建鏡像 有兩種方法構建鏡像&#xff1a; docker commit &#xff1a;將運行的容器保存成鏡像Dockerfile&#xff1a;自動構建 使用docker commit 創建鏡像分為三步&#xff1a; 運行容器修改容器將容器保存為鏡像 舉例&#xff1a; [rootdocker ~]# docker load -i…