QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#300596#4936. Shopping ChangesLeeShoW#Compile Error//C++202.6kb2024-01-08 14:50:562024-01-08 14:50:56

Judging History

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

  • [2024-01-08 14:50:56]
  • 评测
  • [2024-01-08 14:50:56]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h> 
#define int long long
using namespace std;
struct BIT{
    int n;
    vector<int>bit;
    void init(int _n){
        n=_n+1;
        bit=vector<int>(n,0);
    }
    int lowbit(int x){
        return x&-x;
    }
    int query(int x){
        int res=0;
        x++;
        for(;x>0;x-=lowbit(x)){
            res+=bit[x];
        }
        return res;
    }
    void upd(int x,int v){
        x++;
        for(;x<n;x+=lowbit(x)){
            bit[x]+=v;
        }
    }
}a,b,c;
int all[100005];
vector<int>player[100005];
int n,m;
int sol1(){
    int res=0;
    a.init(400005);
    for(int i=n-1;i>=0;i--){
        res+=a.query(all[i]-1);
        a.upd(all[i],1);
    }
    return res;
}
int sol2(int id){
    int res=0;
    int n=player[id].size();
    for(int i=n-1;i>=0;i--){
        //cout<<"Asdas";
        res+=b.query(player[id][i]-1);
        b.upd(player[id][i],1);
    }
    for(int i=0;i<n;i++){
        b.upd(player[id][i],-1);
    }
    return res;
}
signed main() {
    cin>>n>>m;
    vector<int> inq;
    for(int i=0;i<n;i++){
        cin>>all[i];
        inq.push_back(all[i]);
    }
    for(int i=0;i<m;i++){
        int nn;
        cin>>nn;
        while(nn--){
            int k;
            cin>>k;
            player[i].push_back(k);
            inq.push_back(k);
        }
    }
    sort(inq.begin(),inq.end());
    inq.erase(unique(inq.begin(),inq.end()),inq.end());
    for(int i=0;i<n;i++){
        all[i]=lower_bound(inq.begin(),inq.end(),all[i])-inq.begin();
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<player[i].size();j++){
            player[i][j]=lower_bound(inq.begin(),inq.end(),player[i][j])-inq.begin();
        }
    }
    int ans=sol1();//算第一個逆敘述對
    b.init(400005);
    for(int i=0;i<m;i++){
        int now_ans=ans+sol2(i);
        vector<int>suf,pre;
        for(int j=0;j<player[i].size();j++){
            int now=player[i][j];
            pre.push_back(a.query(now-1));
        }
        for(int j=0;j<player[i].size();j++){
            int now=player[i][j];
            suf.push_back(n-a.query(now));
        }
        for(int j=1;j<pre.size();j++){
            pre[j]+=pre[j-1];
        }
        for(int j=suf.size()-2;j>=0;j--){
            suf[j]+=suf[j+1];
        }a
        
        int add=1e15;
        add=min(add,min(pre.back(),suf[0]));
        for(int ii=0;ii<pre.size()-1;ii++){
            add=min(add,pre[ii]+suf[ii+1]);
        }
        cout<<now_ans+add<<endl;
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:102:11: error: expected ‘;’ before ‘long’
  102 |         }a
      |           ^
      |           ;
answer.code:105:9: error: ‘add’ was not declared in this scope; did you mean ‘fadd’?
  105 |         add=min(add,min(pre.back(),suf[0]));
      |         ^~~
      |         fadd