Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
31990 | LYLAKIOI | 【S】T2 | C++ | 通过 | 100 | 122 MS | 15900 KB | 1733 | 2024-08-28 19:54:39 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; const int maxn=5e5+10,mod=998244353; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,q,P[maxn],Q[maxn],t[maxn],tim[maxn];ll s[maxn]; int w[maxn]; struct BIT { int t[maxn]; void clear(){up(i,1,n)t[i]=0;} int lb(int x){return x&(-x);} void upd(int x,int v){for(;x<=n;x+=lb(x))t[x]+=v;} int qry(int x){int res=0;for(;x;x-=lb(x))res+=t[x];return res;} }T; struct BIT2 { int t[maxn]; void clear(){up(i,1,n)t[i]=q+1;} int lb(int x){return x&(-x);} void upd(int x,int v){for(;x<=n;x+=lb(x))t[x]=min(t[x],v);} int qry(int x){int res=q+1;for(;x;x-=lb(x))res=min(res,t[x]);return res;} }T2; void slv(){ n=read(),q=read();up(i,1,n)P[i]=read(),w[i]=q+1; down(i,n,1)t[i]=T.qry(P[i]),T.upd(P[i],1); up(i,1,q)Q[i]=read(),w[Q[i]]=min(w[Q[i]],i); T2.clear(); up(i,1,n){ /*tim[i]=q; up(j,1,q){ if(Q[j]<=i&&P[Q[j]]>=P[i]){tim[i]=j-1;break;} }*/ T2.upd(n-P[i]+1,w[i]); tim[i]=T2.qry(n-P[i]+1)-1; }up(i,1,n)s[tim[i]+1]-=t[i]; ll res=0;up(i,1,n)res+=t[i]; up(i,1,q){ res+=s[i];printf("%lld\n",res); } } int main(){ //freopen("pair.in","r",stdin); //freopen("pair.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }