제출 #530851

#제출 시각아이디문제언어결과실행 시간메모리
530851M1v1savvaArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms296 KiB
#include "shoes.h"
#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define forn(i, x) for (int i = 0; i < (int)x; i++)
#define pb push_back
#define rforn(i, x) for (int i = (int)x - 1; i >= 0; i--)
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second

using namespace std;

template<class T>
void print(T a) {
    for (auto x : a)
        cout << x << ' ';
    cout << endl;
}

long long count_swaps(vector<int> S) {
	vector<int> a = S;
	int n = sz(a);

    map<int, int> prev;

    map<int, int> neg, pos;
    long long ans = 0;
    forn (i, 2 * n) {
    	int val = a[i];
        int val0 = abs(val);
        if (val < 0)
            neg[val0]++;
        else
            pos[val0]++;

		if (neg[val0] > 0 && pos[val0] > 0) {
            neg[val0]--;
            pos[val0]--;
			ans += i - prev[-val];
			if (val > 0)
				ans--;
		} else {
			prev[val] = i;
		}
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...