hdu 1754 模板
来源:互联网 发布:淘宝客服售后怎么做 编辑:程序博客网 时间:2024/04/28 11:20
感觉此模板较好,虽然空间是O(4N)的,但操作简单,不用单写一个构树函数。
代码如下:
#include <cstdio>#include <stack>#include <set>#include <iostream>#include <string>#include <vector>#include <queue>#include <list>#include <functional>#include <cstring>#include <algorithm>#include <cctype>#include <string>#include <map>#include <iomanip>#include <cmath>#define LL long long#define ULL unsigned long long#define SZ(x) (int)x.size()#define Lowbit(x) ((x) & (-x))#define MP(a, b) make_pair(a, b)#define MS(arr, num) memset(arr, num, sizeof(arr))#define PB push_back#define F first#define S second#define ROP freopen("input.txt", "r", stdin);#define MID(a, b) (a + ((b - a) >> 1))#define LC rt << 1, l, mid#define RC rt << 1|1, mid + 1, r#define LRT rt << 1#define RRT rt << 1|1#define BitCount(x) __builtin_popcount(x)#define BitCountll(x) __builtin_popcountll(x)#define LeftPos(x) 32 - __builtin_clz(x) - 1#define LeftPosll(x) 64 - __builtin_clzll(x) - 1const double PI = acos(-1.0);const int INF = 0x3f3f3f3f;using namespace std;const double eps = 1e-5;const int MAXN = 300 + 10;const int MOD = 1000007;const double M=1e-8;const int N=1e6+10;typedef pair<int, int> pii;typedef pair<int, string> pis;const int d[4][2]={{0,1},{0,-1},{-1,0},{1,0}};int n,m,t[N];void updata(int k,int a){ k+=n-1; t[k]=a; while(k>0) { k>>=1; t[k]=max(t[k<<1],t[k<<1|1]); }}int query(int a,int b,int rt,int l,int r){ int i,j; if (b<=l || r<=a) return -1; if (a<=l && r<=b) return t[rt]; else { int u=query(a,b,rt<<1,l,(l+r)>>1); int v=query(a,b,rt<<1|1,(l+r)>>1,r); return max(u,v); }}int main(){ int i,j; while(~scanf("%d%d",&n,&m)) { int r=n; n=1; while(n<r) n*=2; for (i=1;i<=r;i++) { int a; scanf("%d",&a); updata(i,a); } //for (i=1;i<=2*n-1;i++) cout<<t[i]<<" "; cout<<endl; for (i=0;i<m;i++) { char c[2]; int a,b; scanf("%s%d%d",c,&a,&b); if (c[0]=='Q') { cout<<query(a,b+1,1,1,n+1)<<endl; // 查询区间是 [a,b),所以区间右端要加1 } else { updata(a,b); } } }}
0 0
- hdu 1754 模板
- HDU 1754 线段树模板
- Prim 模板 hdu 1879
- hdu 2544 spfa 模板
- HDU 3049 求逆元模板
- HDU 2966 模板题
- KMP 模板 HDU 1711
- spfa模板 hdu 2544
- hdu 1162 prim模板
- HDU 1874 Dijkstra模板
- HDU 1711 KMP模板
- 【HDU 2586】LCA模板
- hdu 1134 大数模板
- HDU 3966 树链剖分模板
- HDU-1711-kmp模板
- RMQ模板hdu 5452
- hdu 5458 树链剖分模板
- HDU 1358 KMP模板
- ArrayList、Hashtable、DataTable、DataView、DataReader和DataSet,DataGrid等的区别和各自的优缺点
- 内存分配
- android 5.0预制APK方法
- 搭建网站IIS目录权限设置说明
- C++【子类的构造和析构】
- hdu 1754 模板
- Ubuntu下NDK环境搭建以及使用
- Android SDK Manager 详解
- CoreAnimation基础
- Linux-iptables原理
- int const * 、const int *、int *const、const char **与char **
- Android.View.InflateException: Binary XML File Line #异常的解决
- 内存分配2
- Shell排序 Java