Submission #957913

# Submission time Handle Problem Language Result Execution time Memory
957913 2024-04-04T13:31:41 Z suren Arranging Shoes (IOI19_shoes) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define S second
#define F first
using namespace std;

ll tree[800045];
bool found[800045];
map < ll, vector<ll> > vc;
void update( ll L, ll R, ll l, ll r, ll node ){
	if( a.size() <= 2000 ){
	
		ll ans = 0, srch;
		for(int i = 0; i < a.size(); i ++ ){
			if( a[i] == 0 )
				continue;
			for(int j = i+1; j < a.size(); j ++ ){
				if( a[j] == -a[i] ){
						ans += j-i;
					if( a[i] < 0 )
						ans --;
					a[j] = 0;
					break;
				}
				if( a[j] == 0 ){
					ans --;
				}
			}
		}
		return ans;
	}
	if( L <= l && r <= R ){
//		cout << "	" << l << " " << r << " " << node << "\n"; 
		if( found[ node ] == 0 && found[node*2] == 0 && found[node*2+1] == 0 )
			found[ node ] = 1;
		tree[node] ++;
		return;
	}
	if( R < l || r < L )
		return;
	if( R < L )
		return;
	ll mid = (l+r)/2;
	if( found[node] == 1 ){
		found[ node*2 ] = 1;
		found[ node*2+1 ] = 1;
		tree[node*2]+= tree[node];
		tree[node*2+1]+= tree[node];
		tree[node] = 0;
	}
	found[ node ] = 0;
	update( L, R, l, mid, node*2 );
	update( L, R, mid+1, r, node*2+1 );
}
ll cnt = 0;
ll query( ll idx, ll l, ll r, ll node ){
	if( found[node] == 1 )
		return tree[node];
	if( l == r )
		return tree[node];
	ll mid = (l+r)/2;
	tree[node*2] += tree[node];
	tree[node*2+1] += tree[node];
	tree[node] = 0;
	if( l <= idx && idx <= mid )
		return query( idx, l, mid, node*2 );
	return query( idx, mid+1, r, node*2+1 );
}
long long count_swaps(std::vector<int> a) {
	ll n = a.size()/2;
	ll ans = 0;
	for(int i = -n; i <= n; i ++ ){
		vc[i].pb( 1 );
	}
	for(int i = 0; i < a.size(); i ++ ){
		vc[ a[i] ].pb( i );
	}
	n = a.size();
	for(int i = 0; i < a.size(); i ++ ){
		if( a[i] == 0 )
			continue;
		ll j = vc[ -a[i] ][ vc[a[i]][0] ];
//		cout << "num " << a[i] << "\n";
//		cout << "real " << i << " " << j << "\n";
		a[j] = 0;
		ll nj = j + query( j, 0, n-1, 1 );
		ll ni = i + query( i, 0, n-1, 1 );
//		cout << "new " << ni << " " << nj << "\n";
		ans += nj-ni;
		if( a[i] < 0 )
			ans --;
//		cout << "updated" << i+1 << " " <<  j-1 << "\n";
		update( i+1, j-1, 0, n-1, 1 );
		vc[ a[i] ][ 0 ] ++;
		vc[ -a[i] ][ 0 ] ++;
//		cout << "tree\n";
//		for(int k = 1; k <= 15; k ++ ){
//			cout << k << ":" << tree[k] << " ";
//		}
//		cout << "\n";
//		for(int k = 1; k <= 15; k ++ ){
//			cout << k << ":" << found[k] << " ";
//		}
//		cout << "\n";
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
shoes.cpp:14:6: error: 'a' was not declared in this scope
   14 |  if( a.size() <= 2000 ){
      |      ^
shoes.cpp:33:10: error: return-statement with a value, in function returning 'void' [-fpermissive]
   33 |   return ans;
      |          ^~~
shoes.cpp:16:15: warning: unused variable 'srch' [-Wunused-variable]
   16 |   ll ans = 0, srch;
      |               ^~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for(int i = 0; i < a.size(); i ++ ){
      |                 ~~^~~~~~~~~~
shoes.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for(int i = 0; i < a.size(); i ++ ){
      |                 ~~^~~~~~~~~~