QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#390825#4772. Movie collectionI_Love_Sonechka#AC ✓70ms5528kbC++171.1kb2024-04-15 22:41:082024-04-15 22:41:09

Judging History

你现在查看的是最新测评结果

  • [2024-04-15 22:41:09]
  • 评测
  • 测评结果:AC
  • 用时:70ms
  • 内存:5528kb
  • [2024-04-15 22:41:08]
  • 提交

answer

#include <bits/stdc++.h>
#include <math.h>
			
using namespace std;

// c++ short types
#define Int long long
#define vt vector

class SegTree {
public:
	vt<int> t;
	int n;
	SegTree(int _n) : n(_n) {
		t = vt<int>(2 * n, 0);
	}
	void update(int pos, int dx) {
		for(pos += n; pos > 0; pos >>= 1) {
			t[pos] += dx;
		}
	}
	int get(int l, int r) {
		int res = 0;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if(l & 1) {
				res += t[l++];
			}
			if(r & 1) {
				res += t[--r];
			}
		}
		return res;
	}
};

void solver() {
	int n, m; cin >> n >> m;
	SegTree st(n + m);
	vt<int> when(n, 0);
	for(int i = 0; i < n; ++i) {
		when[i] = n - i -1;
		st.update(when[i], 1);
	}
	for(int i = 0; i < m; ++i) {
		int id; cin >> id; --id;
		cout << st.get(when[id] + 1, n + m) << " ";
		st.update(when[id], -1);
		when[id] = i + n;
		st.update(when[id], +1);
	}
	cout << "\n";
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	for(int t = 0; t < tt; ++t) {
    solver();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

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: 70ms
memory: 5528kb

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 5...

result:

ok 25 lines