日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Letters Removing CodeForces - 899F (线段树维护序列)

發布時間:2025/3/14 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Letters Removing CodeForces - 899F (线段树维护序列) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

大意: 給定字符串, 每次刪除一段區間的某種字符, 最后輸出序列.

?

類似于splay維護序列. 每次刪除都會影響到后面字符的位置

可以通過轉化為查詢前綴和=k來查找下標.

?

#include <iostream> #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #include <bitset> #define REP(i,a,n) for(int i=a;i<=n;++i) #define PER(i,a,n) for(int i=n;i>=a;--i) #define hr putchar(10) #define pb push_back #define lc (o<<1) #define rc (lc|1) #define mid ((l+r)>>1) #define ls lc,l,mid #define rs rc,mid+1,r using namespace std;const int N = 2e5+10; int n, m; char s[N]; int tr[63][N<<2]; bool vis[63][N<<2]; inline void pu(int o) {REP(i,1,62) tr[i][o]=tr[i][lc]+tr[i][rc]; } inline void pd(int o) {REP(i,1,62) if (vis[i][o]) {tr[i][lc]=0,vis[i][lc]=1;tr[i][rc]=0,vis[i][rc]=1;vis[i][0]=0;} } int get(char x) {if ('0'<=x&&x<='9') return x-'0'+1;if ('A'<=x&&x<='Z') return x-'A'+11;return x-'a'+37; } void build(int o, int l, int r) {if (l==r) ++tr[get(s[l])][o];else build(ls),build(rs),pu(o); } int find(int o, int l, int r, int k) {if (l==r) return l;int s = 0;REP(i,1,62) { if (vis[i][o]) {tr[i][lc]=0,vis[i][lc]=1;tr[i][rc]=0,vis[i][rc]=1;vis[i][o]=0;}else s+=tr[i][lc];}if (s>=k) return find(ls,k);return find(rs,k-s); } void update(int o, int l, int r, int ql, int qr, int v) {if (ql<=l&&r<=qr) return tr[v][o]=0,vis[v][o]=1,void();pd(o);if (mid>=ql) update(ls,ql,qr,v);if (mid<qr) update(rs,ql,qr,v);pu(o); } void dfs(int o, int l, int r) {if (l==r) {if (tr[get(s[l])][o]) printf("%c", s[l]);}else pd(o),dfs(ls),dfs(rs); } int main() {scanf("%d%d%s", &n, &m, s+1);build(1,1,n);REP(i,1,m) {int l, r;char c;scanf("%d%d %c", &l, &r, &c);l=find(1,1,n,l),r=find(1,1,n,r);update(1,1,n,l,r,get(c));}dfs(1,1,n);hr; }

?

轉載于:https://www.cnblogs.com/uid001/p/10764701.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Letters Removing CodeForces - 899F (线段树维护序列)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。