Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34376 | masppy | 【S】T1 | C++ | 运行出错 | 80 | 32 MS | 6704 KB | 1107 | 2024-11-07 18:24:32 |
#include<bits/stdc++.h> #define ll long long #define lson pos<<1 #define rson pos<<1|1 using namespace std; const int maxn=2e5+10; const ll mod=1e9+1; const double inf=1e7+10; ll N,n,k,tot=0,m,ans=0,s,t,cnt,tot1=0; ll a[maxn],b[maxn],fg[maxn],tree[maxn]; char c[maxn]; int root=0; void add(int pos,int x){ for(;pos<=n;pos+=(pos&(-pos))) tree[pos]+=x; } int query(int pos){ int tmp=0; for(;pos;pos-=(pos&(-pos))) tmp+=tree[pos]; return tmp; } int main(){ // freopen("poker.in","r",stdin); // freopen("poker.out","w",stdout); // memset(lst) memset(tree,0,sizeof(tree)); scanf("%lld",&n); scanf("%s",c+1); for(int i=1;i<=n;i++){ fg[i]=c[i]-'0'; } //for(int i) for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); } for(int i=1;i<=n;i++){ scanf("%lld",&b[i]); } ll ans=0; for(int i=1;i<=n;i++){ if((fg[i]+query(i))%2){ ans+=b[i]; add(i,1); add(a[i]+1,-1); } } printf("%lld",ans); fclose(stdin); fclose(stdout); return 0; }