思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> #include<algorithm> #define M 1000001 using namespace std; int A[M],B[M],a[M],s[M],cur,x,q,l,r; char c; int main() { while(scanf("%d",&…
hdu 1754 I Hate It 其实我只是来存一下我的splay模板的..请大牛们多多指教 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std ; const int maxn = 222222 ; int son[2][maxn] , col[maxn] , fa[maxn] , size[maxn] , val[maxn] ; int tot ; int nu…
Get到了全新O(1)替代部分伸展树功能的姿势 左栈stk1维护当前信息,右栈stk2维护历史删除信息 题目求的是严格的前缀和(且小于当前指针)那就每次左栈新增时再更新前缀和信息就好 即使把题面换成最大子段和也是一样搞法 要是O(1)求1到k的最大/小值?再来多一个维护历史的栈..应该可以吧 /*H E A D*/ stack<int> stk1,stk2; ll sum[maxn],maxsum[maxn]; int main(){ int Q,op,x,k; char str[50]; w…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀和,即可 [代码] #include<bits/stdc++.h> using namespace std; ; const int INF = 2e9; class mstack { private : int tot; int s[MAXN]; public : inline void cle…