Submission #161694

# Submission time Handle Problem Language Result Execution time Memory
161694 2019-11-03T18:36:25 Z InkretBear Arranging Shoes (IOI19_shoes) C++14
10 / 100
11 ms 9720 KB
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;

const int MAXN=200000+100;
int fen[MAXN];

int querry(int j){
	if (j==0){
		return 0;
	}
	return fen[j]+querry(j-(j&-j));
}

long long count_swaps(vector<int> a){
	int n=a.size();
	int f=0;
	long long rez=0;
	vector<int> v1[MAXN],v2[MAXN];
	for (int i=0;i<n;++i){
		int curr=a[i];
		if (curr>0){
			v1[curr].push_back(i);
			if (!v2[curr].empty()){
				int x=*--v2[curr].end();
				v2[curr].pop_back();
				v1[curr].pop_back();
				rez+=i+x-2*f-querry(i+1)-querry(x+1)+2*querry(1+2*f)-1;
				for (int j=i+1;j<=MAXN;j+=j&-j){
					++fen[j];
				}
				for (int j=x+1;j<=MAXN;j+=j&-j){
					++fen[j];
				}
				++f;
			}
		}
		else {
			curr*=-1;
			v2[curr].push_back(i);
			if (!v1[curr].empty()){
				int x=*--v1[curr].end();
				v2[curr].pop_back();
				v1[curr].pop_back();
				rez+=i+x-2*f-querry(i+1)-querry(x+1)+2*querry(1+2*f);
				for (int j=i+1;j<=MAXN;j+=j&-j){
					++fen[j];
				}
				for (int j=x+1;j<=MAXN;j+=j&-j){
					++fen[j];
				}
				++f;
			}
		}
	}
	return rez;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Incorrect 10 ms 9720 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Incorrect 11 ms 9720 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9692 KB Output is correct
2 Incorrect 10 ms 9720 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Incorrect 10 ms 9720 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Incorrect 10 ms 9720 KB Output isn't correct
4 Halted 0 ms 0 KB -