QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133545#4936. Shopping ChangesDelay_for_five_minutes#Compile Error//C++141.6kb2023-08-02 10:57:262023-08-02 10:57:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 10:57:30]
  • 评测
  • [2023-08-02 10:57:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=1e5+3;
int n,m,a[N];
vector<int> b[N];
int buc[N*3],tot=0;
struct bit{
    int c[N*3];
    void upd(int x,int y){
        for(;x<=tot;x+=x&-x)c[x]+=y;
    }
    int qry(int x){
        int r=0;
        for(;x;x-=x&-x)r+=c[x];
        return r;
    }
}c1,c2;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        buc[++tot]=a[i];
    }
    for(int i=1;i<=m;++i){
        int k;
        cin>>k;
        b[i].resize(k);
        for(int j=0;j<k;++j){
            cin>>b[i][j];
            buc[++tot]=b[i][j];
        }
    }
    sort(buc+1,buc+tot+1),tot=unique(buc+1,buc+tot+1)-buc-1;
    for(int i=1;i<=n;++i)a[i]=lower_bound(buc+1,buc+tot+1,a[i])-buc;
    for(int i=1;i<=m;++i)
        for(int& x:b[i])
            x=lower_bound(buc+1,buc+tot+1,x)-buc;
    ll s1=0;
    for(int i=1;i<=n;++i){
        s1+=i-1-c1.qry(a[i]-1);
        c1.upd(a[i],1);
    }
    for(int i=1;i<=m;++i){
        int k=b[i].size();
        ll s2=0;
        for(int j=0;j<k;++j){
            s2+=j-c2.qry(b[i][j]);
            c2.upd(b[i][j],1);
        }
        ll s3=0,now=0;
        for(int j=0;j<k3;++j)
            now+=n-c1.qry(b[i][j]);
        s3=now;
        for(int j=0;j<k;++j){
            now+=c1.qry(b[i][j]-1);
            now-=n-c1.qry(b[i][j]);
            s3=min(s3,now);
        }
        //cout<<s1<<' '<<s2<<' '<<s3<<'\n';
        cout<<s1+s2+s3<<'\n';
        for(int j=0;j<k;++j)c2.upd(b[i][j],-1);
    }
}

详细

answer.code: In function ‘int main()’:
answer.code:54:23: error: ‘k3’ was not declared in this scope; did you mean ‘s3’?
   54 |         for(int j=0;j<k3;++j)
      |                       ^~
      |                       s3