제출 #1334446

#제출 시각아이디문제언어결과실행 시간메모리
1334446i271828Arranging Shoes (IOI19_shoes)C++20
15 / 100
12 ms2752 KiB
#include "shoes.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
using namespace std;

const int MAX=1e5+5;

struct FT{
	int A[2*MAX];
	void upd(int x,int a){
		x++;
		while (x>0&&x<2*MAX) A[x]+=a,x+=x&-x;
	}
	int qry(int x){
		x++;
		int a=0;
		while (x>0&&x<2*MAX) a+=A[x],x-=x&-x;
		return a;
	}
	int qry(int x,int y){
		return qry(y)-qry(x-1);
	}
} *ft=new FT();

int N;
set<pii> se;
int opp[MAX];
int pos[MAX];

long long count_swaps(vector<int> A) {
	N=A.size();
	return (N/2*(ll)(N/2-1))/2;
	for (int i=0;i<N;i++){
		auto it=se.lower_bound({-A[i],-1});
		if (it!=se.end()&&it->first==-A[i]) opp[i]=it->second,opp[it->second]=i,se.erase(it);
		else se.insert({A[i],i});
	}
	int j=0;
	for (int i=0;i<N;i++) if (A[i]<0) pos[i]=j,j+=2;
	for (int i=0;i<N;i++) if (A[i]>0) pos[i]=pos[opp[i]]+1;
	for (int i=0;i<N;i++) cout<<opp[i]<<' ';
	cout<<'\n';
	ll ans=0;
	for (int i=0;i<N;i++){
		ans+=ft->qry(pos[i]+1,N-1);
		ft->upd(pos[i],1);
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...