Submission #1110774

# Submission time Handle Problem Language Result Execution time Memory
1110774 2024-11-10T12:55:37 Z epicci23 Arranging Shoes (IOI19_shoes) C++17
45 / 100
43 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]));
 
  int p = 1;
  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);
    c+=F.query(2*n)-F.query(c);
    ans+=c-p;
    p++;

    F.upd(x);
    x+=F.query(2*n)-F.query(x);
    ans+=x-p;
    p++;
  }
 
  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]));
 
  int p = 1;
  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);
    c+=F.query(2*n)-F.query(c);
    ans+=c-p;
    p++;

    F.upd(x);
    x+=F.query(2*n)-F.query(x);
    ans+=x-p;
    p++;
  }
 
  cout << ans << '\n';
}
 
int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory 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 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 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 -
# Verdict Execution time Memory 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 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 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 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 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 4 ms 1104 KB Output is correct
21 Correct 4 ms 1280 KB Output is correct
22 Correct 29 ms 8904 KB Output is correct
23 Correct 28 ms 8904 KB Output is correct
24 Correct 33 ms 8904 KB Output is correct
25 Correct 31 ms 8900 KB Output is correct
26 Correct 40 ms 10180 KB Output is correct
27 Correct 26 ms 8904 KB Output is correct
28 Correct 32 ms 8900 KB Output is correct
29 Correct 34 ms 10352 KB Output is correct
30 Correct 32 ms 10156 KB Output is correct
31 Correct 30 ms 8904 KB Output is correct
32 Correct 32 ms 10708 KB Output is correct
33 Correct 29 ms 8900 KB Output is correct
34 Correct 32 ms 10364 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 33 ms 10628 KB Output is correct
38 Correct 33 ms 10696 KB Output is correct
39 Correct 37 ms 10712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 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 43 ms 11292 KB Output is correct
6 Correct 33 ms 9552 KB Output is correct
7 Correct 39 ms 12616 KB Output is correct
8 Correct 32 ms 10248 KB Output is correct
9 Correct 40 ms 12624 KB Output is correct
10 Correct 42 ms 10056 KB Output is correct
# Verdict Execution time Memory 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 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 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 -
# Verdict Execution time Memory 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 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 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 -