Submission #486812

#TimeUsernameProblemLanguageResultExecution timeMemory
486812HaidaraArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include<shoes.h>
#define rep(i,x,n) for(int i=(x);i<(n);i++)
#define FOR(i,n) rep(i,0,n)
#define v(i) vector< i >
#define ll long long 
using namespace std;
const ll inf=1LL<<62LL;
const ll mod=1e9+7;
const ll maxn=100200;
ll st[maxn];
int n;
int query(int pos,int l=1,int r=n,int inx=1)
{
	if(l==r)
		return st[inx];
	int mid=l+(r-l)/2;
	st[inx*2]+=st[inx];
	st[inx*2+1]+=st[inx];
	st[inx]=0;
	if(pos<=mid)
		return query(pos,l,mid,inx*2);
	return query(pos,mid+1,r,inx*2+1);
}
void update(int ql,int qr,int l=1,int r=n,int inx=1)
{
	if(ql<=l&&r<=qr){
		st[inx]++;
		return ;
	}
	if(ql>r||l>qr)
		return ;
	st[inx*2]+=st[inx];
	st[inx*2+1]+=st[inx];
	st[inx]=0;
	int mid=l+(r-l)/2;
	update(ql,qr,l,mid,inx*2);
	update(ql,qr,mid+1,r,inx*2+1);
}
ll count_swaps(v(int)a)
{
	ll ans=0;
	n=a.size();
	set<int>posl[maxn],posr[maxn];
	FOR(i,n)
	if(a[i]<0)
		posl[-a[i]].insert(i);
	else 
		posr[a[i]].insert(i);
	v(bool)vis(maxn,0);
	FOR(i,n)
	{
		if(vis[i])
			continue;
		if(a[i]>0)
			ans++;
		a[i]=abs(a[i]);
		auto right=*posr[a[i]].begin();
		auto left=*posl[a[i]].begin();
		posl[a[i]].erase(posl[a[i]].begin());
		posr[a[i]].erase(posr[a[i]].begin());
		vis[right]=1;
		vis[left]=1;
		if(left>right)
			swap(left,right);
		ans+=(*right+query(*right+1)-*left-query(*left+1)-1);
			update(*left+1+query(*left+1),*right+1+query(*right+1));
	}
	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:66:9: error: invalid type argument of unary '*' (have 'int')
   66 |   ans+=(*right+query(*right+1)-*left-query(*left+1)-1);
      |         ^~~~~~
shoes.cpp:66:22: error: invalid type argument of unary '*' (have 'int')
   66 |   ans+=(*right+query(*right+1)-*left-query(*left+1)-1);
      |                      ^~~~~~
shoes.cpp:66:32: error: invalid type argument of unary '*' (have 'int')
   66 |   ans+=(*right+query(*right+1)-*left-query(*left+1)-1);
      |                                ^~~~~
shoes.cpp:66:44: error: invalid type argument of unary '*' (have 'int')
   66 |   ans+=(*right+query(*right+1)-*left-query(*left+1)-1);
      |                                            ^~~~~
shoes.cpp:67:11: error: invalid type argument of unary '*' (have 'int')
   67 |    update(*left+1+query(*left+1),*right+1+query(*right+1));
      |           ^~~~~
shoes.cpp:67:25: error: invalid type argument of unary '*' (have 'int')
   67 |    update(*left+1+query(*left+1),*right+1+query(*right+1));
      |                         ^~~~~
shoes.cpp:67:34: error: invalid type argument of unary '*' (have 'int')
   67 |    update(*left+1+query(*left+1),*right+1+query(*right+1));
      |                                  ^~~~~~
shoes.cpp:67:49: error: invalid type argument of unary '*' (have 'int')
   67 |    update(*left+1+query(*left+1),*right+1+query(*right+1));
      |                                                 ^~~~~~