bzoj3192 [JLOI2013]删除物品

题意:

标程:

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 typedef long long ll;
 5 const int N=100005;
 6 int n1,n2,n,a[N],bit[N],b[N];
 7 ll ans;
 8 
 9 int lowbit(int x){return x&(-x);}
10 
11 int qry(int x){int res=0;while (x) res+=bit[x],x-=lowbit(x);return res;}
12 
13 void del(int x) {while (x<=n) bit[x]--,x+=lowbit(x);}
14 
15 bool cmp(int A,int B) {return a[A]>a[B];}
16 
17 int main()
18 {
19     scanf("%d%d",&n1,&n2);
20     for (int i=n1;i>=1;i--) scanf("%d",&a[i]);
21     for (int i=n1+1;i<=n1+n2;i++) scanf("%d",&a[i]);
22     n=n1+n2;
23     for (int i=1;i<=n;i++) b[i]=i,bit[i]=lowbit(i);
24     sort(b+1,b+n+1,cmp);
25     for (int i=1;i<=n;i++)
26     {
27         if (b[i]<=n1) ans+=qry(n1)-qry(b[i]);//在第一段中
28         else ans+=qry(b[i])-qry(n1)-1;//在第二段中 
29         n1=b[i]-1;del(b[i]); 
30     }
31     printf("%lld\n",ans);
32     return 0;
33 } 

 

猜你喜欢

转载自www.cnblogs.com/Scx117/p/9094677.html