# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211105 | _Ice_Tea_ | Arranging Shoes (IOI19_shoes) | C++14 | 78 ms | 26620 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define ULTRA 2134567890
#define de(x) if( x && x == MODE)
#define MODE 0
using namespace std;
int cht[1007][2];
vector<int> keep[100007][2];
int n;
int bit[100007] = {};
bool v[100007] = {};
void add( int x, int d)
{
x++;
while( x <= n)
{
bit[x] += d;
x += x & (-x);
}
}
LLI query( int x)
{
LLI sum = 0;
x++;
while( x)
{
sum += bit[x];
x -= x & (-x);
}
return sum;
}
long long count_swaps(std::vector<int> s) {
int i,j;
n = s.size();
for( i=n-1; i>0; i--)
{
if( s[i] < 0)
keep[ -s[i] ][0].push_back(i);
else
keep[ s[i] ][1].push_back(i);
}
for( i=1; i<n; i++)
add( i, 1);
LLI ans = 0;
for( i=0; i<n; i++)
{
if( v[i])
continue;
de(1)
{
printf(" i = %d\n", i);
}
v[i] = 1;
int color = abs( s[i]);
int match;
if( s[i] < 0)
{
while( v[ keep[color][1].back() ])
keep[color][1].pop_back();
match = keep[color][1].back();
de(1)
{
printf("match = %d\n", match);
}
ans += query( match) - 1;
v[ match ] = 1;
}
else
{
while( v[ keep[color][0].back() ])
keep[color][0].pop_back();
match = keep[color][0].back();
de(1)
{
printf("match = %d\n", match);
}
ans += query( match);
v[ match ] = 1;
}
add( i, -1);
add( match, -1);
de(1) printf("ans = %d\n", ans);
}
return ans;
}
/*
int main()
{
int i,j;
int n;
scanf("%d", &n);
vector<int> s;
for( i=0; i<n; i++)
{
int a;
scanf("%d", &a);
s.push_back(a);
}
LLI ans = count_swaps(s);
printf("%lld\n", ans);
return 0;
}
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |