diff --git a/.ACM-Templates/Josephus_problem.cpp b/.ACM-Templates/Josephus_problem.cpp new file mode 100644 index 0000000..26157ae --- /dev/null +++ b/.ACM-Templates/Josephus_problem.cpp @@ -0,0 +1,12 @@ +///约瑟夫问题,n个人,查m个数 +int JosephusProblem_Solution4(int n, int m) +{ + if(n < 1 || m < 1) + return -1; + + vector f(n+1,0); + for(unsigned i = 2; i <= n; i++) + f[i] = (f[i-1] + m) % i; + + return f[n]; +} diff --git a/.ACM-Templates/RMQ-ST-System.cpp b/.ACM-Templates/RMQ-ST-System.cpp new file mode 100644 index 0000000..ef31d8c --- /dev/null +++ b/.ACM-Templates/RMQ-ST-System.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#define INF 0x3f3f3f3f +using namespace std; +const int maxn = 10010; +struct node +{ + int lt,rt,v; +}; +node tree[maxn<<2]; + +/** ========== Conditional =========== */ +using ValueType = int; + +inline ValueType algo_delegate(ValueType a,ValueType b) +{ + return min(a,b); +} +/****************************************/ + +void build(int lt,int rt,int v) +{ + tree[v].lt = lt; + tree[v].rt = rt; + if(lt == rt) + { + scanf("%d",&tree[v].v); + return; + } + int mid = (lt + rt)>>1; + build(lt,mid,v<<1); + build(mid+1,rt,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +void update(int p,int val,int v) +{ + if(tree[v].lt == tree[v].rt) + { + tree[v].v = val; + return; + } + if(p <= tree[v<<1].rt) update(p,val,v<<1); + if(p >= tree[v<<1|1].lt) update(p,val,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +int query(int lt,int rt,int v) +{ + if(tree[v].lt >= lt && tree[v].rt <= rt) + return tree[v].v; + int a = INF,b = INF; + if(lt <= tree[v<<1].rt) a = query(lt,rt,v<<1); + if(rt >= tree[v<<1|1].lt) b = query(lt,rt,v<<1|1); + return algo_delegate(a,b); +} diff --git a/.Tools/Readme.md b/.Tools/Readme.md index 4bce553..5a500b9 100644 --- a/.Tools/Readme.md +++ b/.Tools/Readme.md @@ -1 +1,2 @@ #Tools +Some tools will be included here to help setup a develop platform on a new computer. diff --git a/HDOJ/1698_sr_19930829.cpp b/HDOJ/1698_sr_19930829.cpp new file mode 100644 index 0000000..b92bdc5 --- /dev/null +++ b/HDOJ/1698_sr_19930829.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +using namespace std; + +#define lson l,m,rt<<1 +#define rson m+1,r,rt<<1|1 +const int maxn=100002; +int col[maxn<<2];//用来标记每个节点,为0则表示没有标记,否则为标记,以颜色的价值作为标记。 +int sum[maxn<<2];//求和 + +void PushUp(int rt)//向上更新和 +{ + sum[rt]=sum[rt<<1]+sum[rt<<1|1]; +} + +void PushDown(int rt,int m)//对某一个区间进行改变,如果被标记了,在查询的时候就得把改变传给子节点,因为查询的并不一定是当前区间 +{//m为区间长度 + if(col[rt])//已经标记过,该区间被改变过 + { + col[rt<<1]=col[rt<<1|1]=col[rt];//标记子节点 + sum[rt<<1]=(m-(m>>1))*col[rt];//更新左儿子的和 + sum[rt<<1|1]=(m>>1)*col[rt];//更新右儿子的和 + col[rt]=0; + } +} + +void build(int l,int r,int rt) +{ + col[rt]=0;//初始化为所有节点均未标记 + sum[rt]=1;//初始值为1 + if(l==r) + return; + int m=(l+r)>>1; + build(lson); + build(rson); +} + +void update(int L,int R,int c,int l,int r,int rt) +{ + if(L<=l&&r<=R) + { + col[rt]=c; + sum[rt]=c*(r-l+1);//更新代表某个区间的节点和,该节点不一定是叶子节点 + return ; + } + PushDown(rt,r-l+1);//向下传递 + int m=(l+r)>>1; + if(L<=m) + update(L,R,c,lson);//更新左儿子 + if(R>m) + update(L,R,c,rson);//更新右儿子 + PushUp(rt);//向上传递更新和 +} +int main() +{ + int k;cin>>k; + int n,c,add,a,b; + for(int i=1;i<=k;i++) + { + scanf("%d",&n); + build(1,n,1); + scanf("%d",&c); + for(int j=1;j<=c;j++) + { + scanf("%d%d%d",&a,&b,&add); + update(a,b,add,1,n,1); + } + printf("Case %d: The total value of the hook is %d.\n",i,sum[1]); + } + return 0; +} diff --git a/POJ/2566_wiking__acm.cpp b/POJ/2566_wiking__acm.cpp new file mode 100644 index 0000000..b4e20d4 --- /dev/null +++ b/POJ/2566_wiking__acm.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +using namespace std; +const int maxn = 100000 + 5; +const int INF = 2000000000; +typedef pair P; +typedef long long LL; + +P p[maxn]; + +int Abs(int x){return x<0?-x:x;} +int n; + +void query(int tar){ + int s = 0,e = 1,Min = INF; + int ansl,ansr,ansx; + while(s <= n && e <= n){ + int tem = p[e].first-p[s].first; + if(Abs(tem-tar) < Min){ + Min = Abs(tem-tar); + ansx = tem; + ansl = p[s].second; + ansr = p[e].second; + } + if(tem > tar) s++; + else if(tem < tar) e++; + else break; + if(s == e) e++; + } + if(ansl > ansr) swap(ansl,ansr); + printf("%d %d %d\n",ansx,ansl+1,ansr); +} + +int main(){ + int m; + while(scanf("%d%d",&n,&m)){ + if(n == 0 && m == 0) break; + p[0] = P(0,0); + int sum = 0; + for(int i = 1;i <= n;i++){ + int tem; + scanf("%d",&tem); + sum += tem; + p[i] = P(sum,i); + } + sort(p,p+n+1); + while(m--){ + int x; + scanf("%d",&x); + query(x); + } + } + return 0; +} diff --git a/hihoCoder/1068.cpp b/hihoCoder/1068.cpp new file mode 100644 index 0000000..192f057 --- /dev/null +++ b/hihoCoder/1068.cpp @@ -0,0 +1,68 @@ +#include +#include +#include + +#include +#include +using namespace std; + +const int MAXN = 1000005; + +int n,ndev; +int a[MAXN]; + +const int MAXDEV = 25; + +int minsum[MAXN][MAXDEV]; + +void RMQ() //预处理->O(nlogn) +{ + for(int j = 1; j <= ndev; ++j) + for(int i = 1; i <= n; ++i) + if(i + (1 << j) - 1 <= n) + { + //maxsum[i][j] = max(maxsum[i][j - 1], maxsum[i + (1 << (j - 1))][j - 1]); + minsum[i][j] = min(minsum[i][j - 1], minsum[i + (1 << (j - 1))][j - 1]); + } +} +int RMQ(int i,int j) +{ + int k=log2( j - i + 1); + //return max(maxsum[i ][ k], maxsum[ j - 2 ^ k + 1][ k]); + return min(minsum[i ][ k], minsum[ j - (1<1) + { + p>>=1; + ndev++; + } + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + Init(); + RMQ(); + int t; + scanf("%d",&t); + for(int i=0;i +#include +#include +#include +using namespace std; + + +const int N = 10e6+10; +const int M = 30; +int arrayData[N]; +int rmqData[N][M]; +int n,m; +int min(int x, int y){ + return (x +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +typedef long long ll; +typedef unsigned int uint; +typedef unsigned long long ull; + +const int maxn = 1e6 + 5; +const int max_pos = 20 ; + +struct Q{ int l,r; } quary[maxn]; + +int N,Q; +int weight[maxn]; +int rmq[maxn][max_pos]; + +void init(){ + memset(rmq,0x5f,sizeof(rmq)); +} + +void input(){ + scanf("%d",&N); + for(int i=1;i<=N;i++) scanf("%d",&weight[i]); + scanf("%d",&Q); + for(int i=1;i<=Q;i++) scanf("%d%d",&quary[i].l,&quary[i].r); +} +/* +int get_mi(int x){ + int ret=0; + for(int i=1;i<=x;i*=2) ret++; + return ret-1; +} +*/ + +void RMQ_ST(){ + for(int i=1;i<=N;i++) rmq[i][0]=weight[i]; + //int l=get_mi(N); + int l=(int)((log(N))/(log(2.0))); + for(int j=1;j<=l;j++){ + for(int i=1;i+(1< +#include +#include +#include +#include +#define INF 0x3f3f3f3f +using namespace std; +const int maxn = 10010; +struct node +{ + int lt,rt,v; +}; +node tree[maxn<<2]; + +/** ========== Conditional =========== */ +using ValueType = int; + +inline ValueType algo_delegate(ValueType a,ValueType b) +{ + return min(a,b); +} +/****************************************/ + +void build(int lt,int rt,int v) +{ + tree[v].lt = lt; + tree[v].rt = rt; + if(lt == rt) + { + scanf("%d",&tree[v].v); + return; + } + int mid = (lt + rt)>>1; + build(lt,mid,v<<1); + build(mid+1,rt,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +void update(int p,int val,int v) +{ + if(tree[v].lt == tree[v].rt) + { + tree[v].v = val; + return; + } + if(p <= tree[v<<1].rt) update(p,val,v<<1); + if(p >= tree[v<<1|1].lt) update(p,val,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +int query(int lt,int rt,int v) +{ + if(tree[v].lt >= lt && tree[v].rt <= rt) + return tree[v].v; + int a = INF,b = INF; + if(lt <= tree[v<<1].rt) a = query(lt,rt,v<<1); + if(rt >= tree[v<<1|1].lt) b = query(lt,rt,v<<1|1); + return algo_delegate(a,b); +} + +int main() +{ + int n,m,op,u,v; + while(~scanf("%d",&n)) + { + build(1,n,1); + scanf("%d",&m); + while(m--) + { + scanf("%d %d %d",&op,&u,&v); + if(op) update(u,v,1); + else printf("%d\n",query(u,v,1)); + } + } + return 0; +} diff --git a/hihoCoder/1070_crackpotisback.cpp b/hihoCoder/1070_crackpotisback.cpp new file mode 100644 index 0000000..34a33f0 --- /dev/null +++ b/hihoCoder/1070_crackpotisback.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LL long long +#define pii pair +#define INF 0x3f3f3f3f +using namespace std; +const int maxn = 10010; +struct node{ + int lt,rt,minv; +}; +node tree[maxn<<2]; +void build(int lt,int rt,int v){ + tree[v].lt = lt; + tree[v].rt = rt; + if(lt == rt){ + scanf("%d",&tree[v].minv); + return; + } + int mid = (lt + rt)>>1; + build(lt,mid,v<<1); + build(mid+1,rt,v<<1|1); + tree[v].minv = min(tree[v<<1].minv,tree[v<<1|1].minv); +} +void update(int p,int val,int v){ + if(tree[v].lt == tree[v].rt){ + tree[v].minv = val; + return; + } + if(p <= tree[v<<1].rt) update(p,val,v<<1); + if(p >= tree[v<<1|1].lt) update(p,val,v<<1|1); + tree[v].minv = min(tree[v<<1].minv,tree[v<<1|1].minv); +} +int query(int lt,int rt,int v){ + if(tree[v].lt >= lt && tree[v].rt <= rt) + return tree[v].minv; + int a = INF,b = INF; + if(lt <= tree[v<<1].rt) a = query(lt,rt,v<<1); + if(rt >= tree[v<<1|1].lt) b = query(lt,rt,v<<1|1); + return min(a,b); +} +int main() { + int n,m,op,u,v; + while(~scanf("%d",&n)){ + build(1,n,1); + scanf("%d",&m); + while(m--){ + scanf("%d %d %d",&op,&u,&v); + if(op) update(u,v,1); + else printf("%d\n",query(u,v,1)); + } + } + return 0; +} diff --git a/hihoCoder/1077.cpp b/hihoCoder/1077.cpp new file mode 100644 index 0000000..6e83e74 --- /dev/null +++ b/hihoCoder/1077.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#define INF 0x3f3f3f3f +using namespace std; +const int maxn = 1000010; +struct node +{ + int lt,rt,v; +}; +node tree[maxn<<2]; + +/** ========== Conditional =========== */ +using ValueType = int; + +inline ValueType algo_delegate(ValueType a,ValueType b) +{ + return min(a,b); +} +/****************************************/ + +void build(int lt,int rt,int v) +{ + tree[v].lt = lt; + tree[v].rt = rt; + if(lt == rt) + { + scanf("%d",&tree[v].v); + return; + } + int mid = (lt + rt)>>1; + build(lt,mid,v<<1); + build(mid+1,rt,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +void update(int p,int val,int v) +{ + if(tree[v].lt == tree[v].rt) + { + tree[v].v = val; + return; + } + if(p <= tree[v<<1].rt) update(p,val,v<<1); + if(p >= tree[v<<1|1].lt) update(p,val,v<<1|1); + tree[v].v = algo_delegate(tree[v<<1].v,tree[v<<1|1].v); +} +int query(int lt,int rt,int v) +{ + if(tree[v].lt >= lt && tree[v].rt <= rt) + return tree[v].v; + int a = INF,b = INF; + if(lt <= tree[v<<1].rt) a = query(lt,rt,v<<1); + if(rt >= tree[v<<1|1].lt) b = query(lt,rt,v<<1|1); + return algo_delegate(a,b); +} + +int main() +{ + int n,m,op,u,v; + while(~scanf("%d",&n)) + { + build(1,n,1); + scanf("%d",&m); + while(m--) + { + scanf("%d %d %d",&op,&u,&v); + if(op) update(u,v,1); + else printf("%d\n",query(u,v,1)); + } + } + return 0; +} diff --git a/hihoCoder/1077_crackpotisback.cpp b/hihoCoder/1077_crackpotisback.cpp new file mode 100644 index 0000000..988b291 --- /dev/null +++ b/hihoCoder/1077_crackpotisback.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LL long long +#define pii pair +#define INF 0x3f3f3f3f +using namespace std; +const int maxn = 1000010; +struct node { + int lt,rt,minv; +}; +node tree[maxn<<2]; +void build(int lt,int rt,int v) { + tree[v].lt = lt; + tree[v].rt = rt; + if(lt == rt) { + scanf("%d",&tree[v].minv); + return; + } + int mid = (lt + rt)>>1; + build(lt,mid,v<<1); + build(mid+1,rt,v<<1|1); + tree[v].minv = min(tree[v<<1].minv,tree[v<<1|1].minv); +} +void update(int p,int val,int v) { + if(tree[v].lt == tree[v].rt) { + tree[v].minv = val; + return; + } + if(p <= tree[v<<1].rt) update(p,val,v<<1); + if(p >= tree[v<<1|1].lt) update(p,val,v<<1|1); + tree[v].minv = min(tree[v<<1].minv,tree[v<<1|1].minv); +} +int query(int lt,int rt,int v) { + if(tree[v].lt >= lt && tree[v].rt <= rt) + return tree[v].minv; + int a = INF,b = INF; + if(lt <= tree[v<<1].rt) a = query(lt,rt,v<<1); + if(rt >= tree[v<<1|1].lt) b = query(lt,rt,v<<1|1); + return min(a,b); +} +int main() { + int n,q,u,v,op; + while(~scanf("%d",&n)) { + build(1,n,1); + scanf("%d",&q); + while(q--) { + scanf("%d %d %d",&op,&u,&v); + if(op) update(u,v,1); + else printf("%d\n",query(u,v,1)); + } + } + return 0; +}