1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include<bits/stdc++.h> #define re register typedef long long ll; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1){ read(x),read(x1...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<> inline void write(bool x){ std::cout<<x; } template<> inline void write(char c){ putchar(c); } template<> inline void write(char *s){ while(*s!='\0') putchar(*s++); } template<> inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...T1> inline void write(T x,T1 ...x1){ write(x),write(x1...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } const int MAXN=3e5+10; const int INF=0x3f3f3f3f; int N,a[MAXN]; char b[MAXN]; struct Segment { #define ls (p<<1) #define rs (p<<1|1) int Tr[MAXN<<2],Len; inline void build(int n) { Len=1; while(Len<=n+1) Len<<=1; } inline void modifyX(int x,int v) { Tr[x+Len]=v; for(int p=(x+Len)>>1;p;p>>=1) Tr[p]=std::max(Tr[ls],Tr[rs]); } inline int queryMax(int l,int r) { if(l>r) return -INF; int res=-INF; for(l+=Len-1,r+=Len+1;l^r^1;l>>=1,r>>=1) { if(~l&1) checkMax(res,Tr[l^1]); if(r&1) checkMax(res,Tr[r^1]); } return res; } #undef ls #undef rs }Up,Down; int Dp[MAXN],ans; int main() {
read(N); for(int i=1;i<=N;++i) read(a[i]); scanf("%s",b+1); Up.build(N),Down.build(N); for(int i=1;i<=N;++i) { Dp[i]=std::max(Up.queryMax(1,a[i]-1),Down.queryMax(a[i]+1,N))+1; if(b[Dp[i]]=='U') Up.modifyX(a[i],Dp[i]); else Down.modifyX(a[i],Dp[i]); checkMax(ans,Dp[i]); } write(ans-1); return 0; }
|
Gitalk 加载中 ...