Submission #1272963

#TimeUsernameProblemLanguageResultExecution timeMemory
1272963arkanefuryArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
#define sz size
#define pb push_back
using namespace std;
const int N = 2e5+5;
int a[N], b[N], t[N*6];
vector<int>g[N];
void upd(int pos, int val, int v = 1, int tl = 1, int tr = n){
	if(tl == tr){
		t[v] = 1;
		return;
	}
	int tm = (tl + tr) >> 1;
	if(pos <= tm)upd(pos, val, v*2, tl, tm);
	else upd(pos, val, v*2+1, tm+1, tr);
	t[v] = t[v*2] + t[v*2+1];
}
int get(int l, int r, int v = 1, int tl = 1, int tr = n){
	if(l <= tl && tr <= r)return t[v];
	if(l > tr || tl > r)return 0;
	int tm = (tl + tr) >> 1;
	return get(l, r, v*2, tl, tm) + get(l, r, v*2+1, tm+1, tr);
}
long long count_swaps(vector <int> v){
    int n = v.sz, k;
    long long ans = 0;
    for(int i = 0; i < n; i ++){
    	if(v[i] < 0)g[abs(v[i]) + n].pb(i);
    	else g[v[i]].pb(i);
	}
	for(int i = 1; i <= 2*n; i ++)reverse(all(g[i]));
	for(int i = 0; i < n; i ++){
		if(b[i])continue;
		if(v[i] < 0){
			int x = abs(v[i]);
			x = g[x][g[x].sz-1];
			k = get(i, x);
			ans += x - i - 1 - k;
			upd(x);
			g[abs(v[i])].pop_back();
		}
		else{
			int x = v[i] + n;
			k = get(i, g[x][g[x].sz-1]);
			ans += g[x][g[x].sz-1] - i - k;
			upd(g[x][g[x].sz-1]);
			g[x].pop_back();
		}
	}
	return ans;
}

Compilation message (stderr)

shoes.cpp:9:60: error: 'n' was not declared in this scope
    9 | void upd(int pos, int val, int v = 1, int tl = 1, int tr = n){
      |                                                            ^
shoes.cpp:19:55: error: 'n' was not declared in this scope
   19 | int get(int l, int r, int v = 1, int tl = 1, int tr = n){
      |                                                       ^
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:3:12: error: cannot convert 'std::vector<int>::size' from type 'std::vector<int>::size_type (std::vector<int>::)() const noexcept' {aka 'long unsigned int (std::vector<int>::)() const noexcept'} to type 'int'
    3 | #define sz size
      |            ^~~~
shoes.cpp:26:15: note: in expansion of macro 'sz'
   26 |     int n = v.sz, k;
      |               ^~
shoes.cpp:32:47: error: 'all' was not declared in this scope
   32 |         for(int i = 1; i <= 2*n; i ++)reverse(all(g[i]));
      |                                               ^~~
shoes.cpp:32:47: note: suggested alternatives:
In file included from /usr/include/c++/13/filesystem:48,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:200,
                 from shoes.cpp:2:
/usr/include/c++/13/bits/fs_fwd.h:154:7: note:   'std::filesystem::perms::all'
  154 |       all               =  0777,
      |       ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:89:
/usr/include/c++/13/ranges:1308:27: note:   'std::ranges::views::all'
 1308 |     inline constexpr _All all;
      |                           ^~~
shoes.cpp:3:12: error: invalid use of member function 'constexpr std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
    3 | #define sz size
      |            ^
shoes.cpp:37:39: note: in expansion of macro 'sz'
   37 |                         x = g[x][g[x].sz-1];
      |                                       ^~
shoes.cpp:40:28: error: too few arguments to function 'void upd(int, int, int, int, int)'
   40 |                         upd(x);
      |                         ~~~^~~
shoes.cpp:9:6: note: declared here
    9 | void upd(int pos, int val, int v = 1, int tl = 1, int tr = n){
      |      ^~~
shoes.cpp:3:12: error: invalid use of member function 'constexpr std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
    3 | #define sz size
      |            ^
shoes.cpp:45:46: note: in expansion of macro 'sz'
   45 |                         k = get(i, g[x][g[x].sz-1]);
      |                                              ^~
shoes.cpp:3:12: error: invalid use of member function 'constexpr std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
    3 | #define sz size
      |            ^
shoes.cpp:46:42: note: in expansion of macro 'sz'
   46 |                         ans += g[x][g[x].sz-1] - i - k;
      |                                          ^~
shoes.cpp:3:12: error: invalid use of member function 'constexpr std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
    3 | #define sz size
      |            ^
shoes.cpp:47:39: note: in expansion of macro 'sz'
   47 |                         upd(g[x][g[x].sz-1]);
      |                                       ^~