답안 #1110752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110752 2024-11-10T10:34:56 Z epicci23 Arranging Shoes (IOI19_shoes) C++17
45 / 100
39 ms 12624 KB
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()

struct Fenwick{
  vector<int64_t> fw;
  int N;
  Fenwick(int64_t _n){
  	N = _n + 15;
  	fw.assign(N,0);
  }
  void upd(int64_t c){
    for(;c<N;c+=c&-c) fw[c]--;
  }
  int64_t query(int64_t c,int64_t res=0){
  	for(;c;c-=c&-c) res+=fw[c];
  	return res;
  }
};

int64_t count_swaps(vector<int> S){
  int64_t n , ans = 0; 
  n = sz(S) / 2;
  int64_t ar[2 * n + 5];
  for(int i=1;i<=2*n;i++) ar[i] = S[i - 1];
  
  queue<int64_t> q;
  vector<int64_t> pos[n+5];

  Fenwick F(2*n);

  for(int i=1;i<=2*n;i++){
    if(ar[i]<0) q.push(i);
    else pos[ar[i]].push_back(i);
  }
  
  for(int i=1;i<=n;i++) reverse(all(pos[i]));

  while(!q.empty()){
  	int64_t c = q.front();
  	q.pop();
  	int64_t x = pos[-ar[c]].back();
  	pos[-ar[c]].pop_back();
  	F.upd(c + 1);
  	ans += c + F.query(c) - 1;
  	F.upd(x + 1);
  	ans += x + F.query(x) - 1;
  }

  return ans;
}


/*void _(){
  int n,ans=0; cin >> n;
  int ar[2*n+5];
  for(int i=1;i<=2*n;i++) cin >> ar[i];
  
  queue<int> q;
  vector<int> pos[n+5];

  Fenwick F(2*n);

  for(int i=1;i<=2*n;i++){
    if(ar[i]<0) q.push(i);
    else pos[ar[i]].push_back(i);
  }
  
  for(int i=1;i<=n;i++) reverse(all(pos[i]));

  while(!q.empty()){
  	int c = q.front();
  	q.pop();
  	int x = pos[-ar[c]].back();
  	pos[-ar[c]].pop_back();
  	F.upd(c + 1);
  	ans += c + F.query(c) - 1;
  	F.upd(x + 1);
  	ans += x + F.query(x) - 1;
  }

  cout << ans << '\n';
}

int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Incorrect 1 ms 336 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 4 ms 1360 KB Output is correct
21 Correct 4 ms 1392 KB Output is correct
22 Correct 28 ms 10184 KB Output is correct
23 Correct 26 ms 10184 KB Output is correct
24 Correct 30 ms 10184 KB Output is correct
25 Correct 30 ms 9924 KB Output is correct
26 Correct 29 ms 10188 KB Output is correct
27 Correct 26 ms 10180 KB Output is correct
28 Correct 33 ms 10180 KB Output is correct
29 Correct 33 ms 10176 KB Output is correct
30 Correct 31 ms 10180 KB Output is correct
31 Correct 29 ms 10184 KB Output is correct
32 Correct 31 ms 10504 KB Output is correct
33 Correct 32 ms 9916 KB Output is correct
34 Correct 30 ms 10152 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 31 ms 10696 KB Output is correct
38 Correct 32 ms 10696 KB Output is correct
39 Correct 34 ms 10568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 39 ms 12624 KB Output is correct
6 Correct 34 ms 10832 KB Output is correct
7 Correct 39 ms 12624 KB Output is correct
8 Correct 30 ms 10240 KB Output is correct
9 Correct 39 ms 12616 KB Output is correct
10 Correct 39 ms 11336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Incorrect 1 ms 336 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Incorrect 1 ms 336 KB Output isn't correct
15 Halted 0 ms 0 KB -