hdu 1754/zstu 3121 I Hate It(線段樹)

?http://acm.hdu.edu.cn/showproblem.php?pid=1754

http://acm.zstu.edu.cn:8080/JudgeOnline/showproblem?problem_id=3121

(1)線段樹的基本操作:建樹,查詢,更新。

(2)重新寫一遍時,發現有個比較神奇的超時:假如主函數中少寫了:

for(i=1;i<=m;i++)

   案例是可以過的,提交狀態為TLE。。(這種情況與輸入的結構有關,起初還以為是其它函數功能沒寫好)

(3)又寫了一遍,把操作次數的循環寫成了(RE):

for(i=1;i<=n;i++)

?

具體代碼:

View Code
#include<stdio.h>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int N=201000<<2;
int n, m;
int data[N], Max[N];
void pushback(int rt)
{Max[rt]=max(Max[rt<<1], Max[rt<<1|1]);
}
void build(int l, int r, int rt)
{if(l==r){scanf("%d", &data[l]);Max[rt]=data[l];return ;}int m=l+r>>1;build(lson);build(rson);pushback(rt);
}
int query(int L, int R, int l, int r, int rt)
{if(L<=l&&r<=R){return Max[rt];}int m=l+r>>1;int ret=0;if(L<=m) ret=max(ret, query(L, R, lson));if(R>m) ret=max(ret, query(L, R, rson));return ret;
}
void update(int p, int ne, int l, int r, int rt)
{if(l==r){Max[rt]=ne;return ;}int m=l+r>>1;if(p<=m) update(p, ne, lson);else update(p, ne, rson);pushback(rt);
}
int main()
{int i, j;while(scanf("%d%d", &n, &m)!=EOF){build(1, n, 1);for(i=1;i<=m;i++){int a, b;char c;scanf(" %c%d%d", &c, &a, &b);if(c=='Q'){printf("%d\n", query(a, b, 1, n, 1));}else if(c=='U'){update(a, b, 1, n, 1);}}}return 0;
}

?

轉載于:https://www.cnblogs.com/tim11/archive/2012/08/21/2648953.html

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

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

相關文章

sketch放入app組件_使用Sketch App設計CSS網格

sketch放入app組件首先定義您的網格 (Start by defining your grid) Sketch has 2 built-in layout features — Layout and Grid. In most cases, layout is a great way to organize content on a typical website utilizing a 12 column grid. However for this exercise we…

鮮為人知的CSS實用技巧

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

獵鷹spacex_我如何重新創建SpaceX儀表板UI

獵鷹spacexA couple of weeks ago, SpaceX Crew Dragon launched from Kennedy Space Center to transport astronauts Robert L. Behnken and Douglas G. Hurley to the ISS. Lots of things were revolutionary about this launch, but the one that caught my attention was…

Base64 編碼原來這么簡單

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

spring事物 設計模式_是什么使事物變得美麗,以及如何在設計中使用它

spring事物 設計模式What do you think about the phrase “beautiful design”? You like it, don’t care or does it make you wince?w ^帽子你想想那句“美麗的設計”&#xff1f; 您喜歡它&#xff0c;不在乎還是讓自己畏縮了&#xff1f; For many, “beautiful” is …

直接插入排序(Straight Insertion Sort)

將一個數組,按當前元素的大小,插入到前面已經排好序的數據中的適當位置中,依次直到全入插入完全.下面是一個數組在經過插入排序時的變化情況(t表次數times)Init---{7, 4, 3, 2, 5, 6, 1} 初始t1----{4, 7, 3, 2, 5, 6, 1} 將第1個元素按其大小插到前面排好序的數列的相應位置…

歷時一個月!50+Vue經典面試題詳解,值得收藏!

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

頁面滾動時觸發圖片逐幀播放_如何在滾動效果上創建逐幀運動圖像

頁面滾動時觸發圖片逐幀播放A step by step guide on how to create that dynamic image background you see everywhere.有關如何創建隨處可見的動態圖像背景的逐步指南。 內容 (Content) Introduction 介紹 Result demo 結果演示 Prerequisite 先決條件 Step by step guide …

hdu 4391 Paint The Wall 線段樹 +優化 2012 Multi-University Training Contest 10 )

http://acm.hdu.edu.cn/showproblem.php?pid4391題意&#xff1a;刷墻&#xff0c; 以開始 有 n個節點&#xff0c;每個節點有一種顏色 &#xff0c;m 次詢問m次 輸入 a&#xff0c;l&#xff0c;r&#xff0c;z 如果 a1 將 l到 r 刷為 z 顏色&#xff0c;如果 a2 詢問 l 到…

前端監控的搭建步驟,別再一頭霧水了!

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

1812:網格_指導設計:網格的歷史

1812:網格The grid has long played a central role in the development of art and design due to its organizational nature; acting as a matrix for controlling the placement of elements. In art: Foreground and background. In design: Image and type. And so on.網…

HDU ACM 1728 逃離迷宮 (廣搜BFS)

http://acm.hdu.edu.cn/showproblem.php?pid1728 題意:給出一張圖,轉彎數k,起點(x1,y1),(x2,y2)判斷能不能最多只轉k個彎時從起點走到終點 輸入時注意起點與終點是先y后x的 思路:用point[4][2]表示方向向量,每次遍歷遍歷一行或者一列,遍歷時要注意遇到遍歷過的點要跳過去,繼續…

Element使用的async-validator表單校驗庫源碼超詳細解析

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

從零手寫 Vue 之響應式系統

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

WPF 分頁控件應用

效果圖&#xff1a; 前臺代碼&#xff1a; <UserControl x:Class"Layout.UI.Comm.Pager"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc"http:/…

李寧品牌重塑_邁伊多品牌重塑的幕后

李寧品牌重塑This post was originally published on the Maido blog.這篇文章最初發表在 Maido博客上 。 You might notice that we’ve had a little facelift at Maido. Or you might not — and that’s totally fine. What we launched at the end of last year was not r…

搭建前端監控,如何采集異常數據?

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

產品經理如何提高創造力_如何提高產品設計師的創造力

產品經理如何提高創造力When David Kelley, Bill Moggridge, and Mike Nuttall founded IDEO, a consulting firm that would become one of the most innovative companies of the late 90s, they brought a new perspective in product development.當大衛凱利(David Kelley)…

Github上8個很棒的Vue項目

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

域名解析文件hosts文件是什么?如何修改hosts文件?

如何修改hosts文件&#xff1f; hosts文件的位置&#xff1a;xp,2000等系統在 C:\windows\system32\drivers\etc 文件夾中找到Hosts文件并用記事本打開(Windows 9x/Me系統在C:\Windows文件夾中找)按照 ip地址 域名 的格式添加單獨的一行記錄。例如72.14.219.190 www.hbcms.net…