Submission #965377

# Submission time Handle Problem Language Result Execution time Memory
965377 2024-04-18T12:04:51 Z Syrius Arranging Shoes (IOI19_shoes) C++14
0 / 100
451 ms 547140 KB
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;

// #define int long long
#define ll long long
#define ff first
#define ss second
#define pint pair < int , int >
#define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL)

const int inf = 1e9 + 9;
const int mxn = 2e5 + 2;
const int mod = 1e9 + 7;

int fn[mxn];
void update(int x , int v) {
	for (; x <= mxn; x += x&-x) {
		fn[x] += v;
	}
}

int query(int l , int r) {
	int ans = 0;
	l--;
	for (; r > 0; r -= r&-r) ans += fn[r];
	for (; l > 0; l -= l&-l) ans -= fn[l];
}

ll count_swaps(vector < int > v) {

	int n = v.size() / 2;
	bool b[mxn];

	queue < int > left[mxn] , right[mxn];
	for (int i = 0; i < 2 * n; i++) {
		if (v[i] < 0) left[v[i]].push(i);
		else right[v[i]].push(i);
		update(i+1 , 1);
	}

	int ans = 0;
	for (int i = 0; i < 2*n; i++) {
		if (b[i]) continue;
		int id;
		if (v[i] < 0) {
			id = right[v[i]].front();
			right[v[i]].pop();
			ans += query(i+2 , id);
			update(id+1 , -1);
		} else {
			id = left[v[i]].front();
			left[v[i]].pop();
			ans += query(i+2 , id) + 1;
			update(id+1 , -1);
		}
		b[id] = 1;
	}
	
	return ans;
}

Compilation message

shoes.cpp: In function 'int query(int, int)':
shoes.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
   28 | }
      | ^
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:37:26: warning: array subscript -1 is below array bounds of 'std::queue<int> [200002]' [-Warray-bounds]
   37 |   if (v[i] < 0) left[v[i]].push(i);
      |                 ~~~~~~~~~^
shoes.cpp:37:26: warning: array subscript -1 is below array bounds of 'std::queue<int> [200002]' [-Warray-bounds]
shoes.cpp:37:26: warning: array subscript -1 is below array bounds of 'std::queue<int> [200002]' [-Warray-bounds]
shoes.cpp:44:10: warning: ''target_mem_ref' not supported by dump_expr<expression error>' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   if (b[i]) continue;
      |       ~~~^
# Verdict Execution time Memory Grader output
1 Runtime error 451 ms 547140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 451 ms 547140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 451 ms 547140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 322 ms 546692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 451 ms 547140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 451 ms 547140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -