Submission #62559382
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;typedef long long ll;struct Fenw {int n;vector<int> tree;Fenw(int n): n(n), tree(n+1, 0) { }void init() {for (int i = 1; i <= n; i++) tree[i] = 0;}void update(int i, int delta){for(; i <= n; i += i & -i)tree[i] += delta;}int sum(int i){int s = 0;for(; i > 0; i -= i & -i)s += tree[i];return s;}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Fenw {
int n;
vector<int> tree;
Fenw(int n): n(n), tree(n+1, 0) { }
void init() {
for (int i = 1; i <= n; i++) tree[i] = 0;
}
void update(int i, int delta){
for(; i <= n; i += i & -i)
tree[i] += delta;
}
int sum(int i){
int s = 0;
for(; i > 0; i -= i & -i)
s += tree[i];
return s;
}
// kth 1-indexed free position
int findKth(int k){
int pos = 0;
for (int bit = 1 << 20; bit > 0; bit >>= 1){
int nextPos = pos + bit;
if (nextPos <= n && tree[nextPos] < k) {
k -= tree[nextPos];
pos = nextPos;
}
}
return pos + 1;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> P(N+1);
for (int i = 1; i <= N; i++){
cin >> P[i];
}
// BIT(1-indexed)で初期状態は全て空(1が埋まっているとみなす)
Fenw fenw(N);
for (int i = 1; i <= N; i++){
fenw.update(i, 1);
}
vector<int> res(N+1, 0);
// i = N downto 1 で、P[i] 番目の空き位置に i を配置する
for (int i = N; i >= 1; i--){
int k = P[i];
int pos = fenw.findKth(k);
res[pos] = i;
fenw.update(pos, -1); // pos を利用済みにする
}
// 1-indexedの位置順に出力
for (int i = 1; i <= N; i++){
cout << res[i] << (i==N ? "\n" : " ");
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Insert |
| User | una_o0 |
| Language | C++ 20 (gcc 12.2) |
| Score | 500 |
| Code Size | 1676 Byte |
| Status | AC |
| Exec Time | 140 ms |
| Memory | 9756 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| min.txt | AC | 1 ms | 3408 KiB |
| random_01.txt | AC | 140 ms | 9756 KiB |
| random_02.txt | AC | 44 ms | 5188 KiB |
| random_03.txt | AC | 139 ms | 9676 KiB |
| random_04.txt | AC | 21 ms | 4112 KiB |
| random_05.txt | AC | 139 ms | 9676 KiB |
| random_06.txt | AC | 57 ms | 5876 KiB |
| random_07.txt | AC | 139 ms | 9724 KiB |
| random_08.txt | AC | 9 ms | 3556 KiB |
| random_09.txt | AC | 71 ms | 9648 KiB |
| random_10.txt | AC | 73 ms | 9740 KiB |
| random_11.txt | AC | 79 ms | 9640 KiB |
| random_12.txt | AC | 81 ms | 9676 KiB |
| random_13.txt | AC | 82 ms | 9740 KiB |
| random_14.txt | AC | 84 ms | 9680 KiB |
| random_15.txt | AC | 100 ms | 9676 KiB |
| random_16.txt | AC | 100 ms | 9640 KiB |
| sample_01.txt | AC | 1 ms | 3632 KiB |
| sample_02.txt | AC | 1 ms | 3584 KiB |