QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650070 | #4772. Movie collection | SGColin# | AC ✓ | 32ms | 4944kb | C++20 | 1.2kb | 2024-10-18 12:27:20 | 2024-10-18 12:27:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const int N = 200007;
int n, m;
struct BIT {
#define lowbit(x) ((x) & (-(x)))
int c[N];
void reset() {rep(i, 0, n + m) c[i] = 0;}
void upd(int p, int w) {
for (; p < N; p += lowbit(p)) c[p] += w;
}
int sum(int p) {
int ret = 0;
for (; p; p -= lowbit(p)) ret += c[p];
return ret;
}
} bit;
int pos[N];
inline void work() {
n = rd(); m = rd(); bit.reset();
int tot = m + 1;
rep(i, 1, n) pos[i] = m + i;
rep(i, 1, m) {
int x = rd();
printf("%d", pos[x] - tot - bit.sum(pos[x]));
bit.upd(pos[x], 1);
pos[x] = --tot;
putchar(i == m ? '\n' : ' ');
}
}
int main() {
per(t, rd(), 1) work();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
input:
2 3 3 3 1 1 5 3 4 4 5
output:
2 1 0 3 0 4
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 32ms
memory: 4944kb
input:
25 3 3 3 1 1 5 3 4 4 5 84 887 10 20 30 32 11 73 58 74 3 20 63 68 84 71 25 79 17 17 60 57 76 10 3 27 27 56 44 20 6 43 67 55 18 52 2 29 80 59 58 82 34 36 21 74 63 45 24 79 18 83 8 9 9 10 75 75 65 74 10 70 33 76 81 6 83 82 74 78 13 4 31 46 39 52 75 57 52 15 8 25 13 15 33 61 64 24 51 44 13 61 69 1 8 65 ...
output:
2 1 0 3 0 4 9 19 29 31 13 72 58 73 10 7 64 69 83 73 33 79 28 0 66 65 77 18 12 39 0 66 55 15 26 55 73 67 38 65 29 47 80 69 27 82 53 55 47 31 31 62 51 29 15 83 43 44 0 28 80 0 76 11 3 79 59 33 83 29 11 20 8 83 52 49 61 69 66 32 17 41 2 57 21 45 10 3 18 77 79 27 76 43 7 5 81 57 11 28 74 60 64 38 72 55 ...
result:
ok 25 lines