比赛 EYOI暨SBOI暑假快乐赛6th 评测结果 WWWWTTTTTT
题目名称 千风的诗篇 最终得分 0
用户昵称 遥时_彼方 运行时间 6.755 s
代码语言 C++ 内存使用 8.25 MiB
提交时间 2022-06-30 11:36:25
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
	int x=0;bool flag=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	if(flag) return x;
	return ~(x-1);
} 
inline void write(ll x)
{
	if(x<0) {x=~(x-1);putchar('-');}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
/////////////////////////
const int N=1e5+50;
int nc,mc;
int n[N];
int _n[N];
ll a1[N],a2[N];//左侧大,左侧小 
ll b1[N],b2[N];//右侧大,右侧小 
ll f1[N];
ll sum;
inline int lowbit(int x){return x&(-x);}
inline ll fin(int x)
{
    ll re=0;
    for(;x;x-=lowbit(x)) re+=f1[x];
    return re;    
} 
inline void get_in(int x){for(;x<=nc;x+=lowbit(x)) f1[x]++;}
//inline ll FIN(int x,int y)
//{
//    ll re=0;
//    for(;x;x-=lowbit(x))
//        for(int o=y;o;o-=lowbit(o)) re+=
//}
int main()
{
    freopen("windy.in","r",stdin);
	freopen("windy.out","w",stdout);
    nc=read(),mc=read();
    rep(i,1,nc)
    {
        n[i]=read();
        a2[i]=fin(n[i]);
        a1[i]=i-1-a2[i];
        b2[i]=n[i]-1-a2[i];
        b1[i]=nc-n[i]-a1[i];
        sum+=a2[i];
        get_in(n[i]);
        _n[n[i]]=i;
    }
    int s1;
    rep(i,1,mc)
    {
//        cout<<"S:";
        write(sum);
        putchar(10);
        s1=read();
        n[_n[s1]]=0;
        rep(i,1,_n[s1])
        {
            if(!n[i]) continue;
            if(n[i]>s1) sum--;
        }
//        cout<<"N:"<<_n[s1]<<endl;
        rep(i,_n[s1]+1,nc)
        {
            if(!n[i]) continue;
            if(n[i]<s1) sum--;
        }
//        sum-=(a1[_n[s1]]+b2[_n[s1]]);
//        sum+=FIN(_n[s1],nc);
//        sum+=FIN(nc,s1);
//        sum-=(FIN(_n[s1],s1)<<1);
//        GET_IN(_n[s1],s1);
    }
    return 0;
}