luogu P1198 [JSOI2008]最大数

准备写线段树写法

所以先搁置一下23333

啊我debug半个点失败

可能我今天不适合写题解【微笑

拖图片拖了五分钟,总是一点就变成预览模式

气得我想砸电脑

mmp

线段树写法也没写出来

心情好差www

啊好的发泄完毕好轻松

emmmm

那么我们来看一下这道题吧

线段树的单点修改啊,还不用建树!

(可是我没写出来23333【气死

然后谢谢题解

因为每次都在尾端插入

所以可以用st表来写

还是很好理解的思路

#include<cstdio>#include<algorithm>#include<cmath>#include<iostream>using namespace std;#define maxn 200010int dp[maxn][21],cnt,b[maxn];void add(int x){ dp[++ cnt][0] = x; for(int i = 1;cnt - (1 << i) >= 0;i++) dp[cnt][i] = max(dp[cnt][i - 1],dp[cnt - (1 << (i - 1))][i - 1]);}int query(int x){ int k = log2(cnt - x + 1); return max(dp[cnt][k],dp[x - 1 + (1 << k)][k]);}int main(){ int m,mod,last = 0; scanf("%d%d",&m,&mod); for(int i = 1;i <= m;i++){ char ch; cin >> ch; if(ch == A){ int x; scanf("%d",&x); int qwq = (x + last) % mod; add(qwq); } else{ int y; scanf("%d",&y); int ans = query(cnt - y + 1); last = ans; printf("%d\n",ans); } } return 0;}

每次写st表的时候都会忍不住想起zyr学长通俗易懂的st表讲解

tql!!!

(突然想起来还有作业【扔下水的一批的题解然后溜

 

相关文章