Submission #1015445

#TimeUsernameProblemLanguageResultExecution timeMemory
1015445nam6Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std; 
#define int long long

const int MAXI = 200*1000;
queue<int> occ[2*MAXI]; 
bool dejaVu[MAXI]; 

const int DECA = 1<<21; 
int arbre[2*DECA]; 

void modif(int pos){
	pos+=DECA; 
	arbre[pos] = 1; 
	while(pos>1){
		pos/=2; 
		arbre[pos] = arbre[2*pos] + arbre[2*pos+1]; 
	}
}

int calcSomme(int deb, int fin){
	if(deb==fin)
		return arbre[deb]; 
	if(deb%2==1)
		return arbre[deb] + calcSomme(deb+1, fin); 
	if(fin%2==0)
		return calcSomme(deb, fin-1) + arbre[fin]; 
	return calcSomme(deb/2, fin/2); 
}


long long count_swaps(vector<int> s) {
	int nb = s.size();
	//cout << nb << endl; 
	for(int c=0; c<nb; c++){
		//cout << s[c] << endl;
		occ[MAXI + s[c]].push(c); 
	}
	int res = 0; 
	for(int g=0; g<nb; g++){
		if(!dejaVu[g]){
			int d = occ[MAXI - s[g]].front(); 
			occ[MAXI - s[g]].pop(); 
			occ[MAXI + s[g]].pop(); 
			dejaVu[d] = true; 
			if(s[g] < 0){    // si chaussure gauche
				res += d-g-1; 
			}
			else{ // si chaussure droite
				res+= d-g; 
			}
			res -= calcSomme(g+DECA, d+DECA);
			modif(d); 
		}
	}

	return res;
}

signed main() {
	int n;
	assert(1 == scanf("%d", &n));
	vector<int> S(2 * n);
	for (int i = 0; i < 2 * n; i++) {
		cin >> S[i];//assert(1 == scanf("%d", &S[i]));
		//cout << S[i] << endl;
	}
	fclose(stdin);

	long long result = count_swaps(S);

	printf("%lld\n", result);
	fclose(stdout);
	return 0;
}

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from shoes.cpp:1:
shoes.cpp: In function 'int main()':
shoes.cpp:62:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   62 |  assert(1 == scanf("%d", &n));
      |                    ^~~~  ~~
      |                          |
      |                          long long int*
shoes.cpp:62:22: note: format string is defined here
   62 |  assert(1 == scanf("%d", &n));
      |                     ~^
      |                      |
      |                      int*
      |                     %lld
/usr/bin/ld: /tmp/cc8k5mjL.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccYVDGfM.o:shoes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc8k5mjL.o: in function `main':
grader.cpp:(.text.startup+0x29d): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status