# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
268110 | 2020-08-16T08:51:13 Z | shinjan | Arranging Shoes (IOI19_shoes) | C++14 | 1 ms | 256 KB |
#include <iostream> #include <bits/stdc++.h> #include "shoes.h" #define maxN 100001 using namespace std; int fen[maxN]; void add(int ind,int n) { for(int i=ind;i<=n;i+=(i&(-i))) { fen[i]++; } } void brisi(int ind,int n) { for(int i=ind;i<=n;i+=(i&(-i))) { fen[i]--; } } long long sum(int ind) { long long ans=0; for(int i=ind;i>=1;i-=(i&(-i))) { ans+=fen[i]; } return ans; } long long count_swaps(vector <int> s) { int n=s.size(); long long ans=0; queue<int> neg[n/2+1]; queue<int> poz[n/2+1]; for(int i=0;i<s.size();i++) { if(s[i]>0) { if(neg[s[i]].size()!=0) { int pos=neg[s[i]].front(); ans-=(sum(i)-sum(pos+1)); brisi(pos+1,n); ans+=(i-pos); neg[s[i]].pop(); } else{ poz[s[i]].push(i); add(i+1,n); } } if(s[i]<0) { int x=abs(s[i]); if(poz[x].size()!=0) { int pos=poz[x].front(); ans-=(sum(i)-sum(pos+1)); brisi(pos+1,n); ans+=(i-pos+1); poz[x].pop(); } else{ neg[x].push(i); add(i+1,n); } } } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |