QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612086#6701. BaoBao Loves Readingkevinyang#AC ✓118ms12064kbC++141.6kb2024-10-05 05:15:002024-10-05 05:15:00

Judging History

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

  • [2024-10-05 05:15:00]
  • 评测
  • 测评结果:AC
  • 用时:118ms
  • 内存:12064kb
  • [2024-10-05 05:15:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct BIT{
	vector<int>arr;
	int size;
	void init(int n){
		size = n;
		arr.resize(n+5);
	}
	void update(int x, int val){
		for(int a = x; a<=size; a+=a&-a){
			arr[a]+=val;
		}
	}
	int query(int x){
		int sum = 0;
		for(int a = x; a>0; a-=a&-a){
			sum+=arr[a];
		}
		return sum;
	}
	void change(int x, int val){
		int v = query(x)-query(x-1);
		update(x,val-v);
	}
	int query(int x, int y){//inclusive
		return query(y)-query(x-1);
	}
};

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int>a(n+1);
		for(int i = 1; i<=n; i++){
			cin >> a[i];
		}
		vector<vector<int>>idx(n+1);
		for(int i = 1; i<=n; i++){
			idx[a[i]].push_back(i);
		}
		BIT bit;
		bit.init(n+1);
		vector<int>queries(n+1);
		for(int i = 1; i<=n; i++){
			for(int j = 1; j<idx[i].size(); j++){
				queries[idx[i][j]] = idx[i][j-1];
			}
		}
		vector<int>last(n+1);
		vector<int>psa(n+1);
		psa[1] = n;
		for(int i = 1; i<=n; i++){
			if(last[a[i]]){
				bit.update(last[a[i]],-1);
			}
			bit.update(i,1);
			last[a[i]] = i;
			if(queries[i]){
				int v = bit.query(queries[i],i);
				psa[v]--;
			}
		}
		for(int i = 1; i<=n; i++){
			psa[i]+=psa[i-1];
		}
		for(int i = 1; i<=n; i++){
			cout << psa[i];
			if(i<n)cout << ' ';
		}
		cout << '\n';
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

1
7
4 3 4 2 3 1 4

output:

7 6 5 4 4 4 4

result:

ok single line: '7 6 5 4 4 4 4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

100
73
45 45 2 2 2 45 35 45 16 35 16 45 35 2 16 16 45 2 45 45 16 35 35 16 35 35 2 2 2 35 45 35 45 35 16 35 2 2 16 35 16 45 45 16 45 2 16 16 35 16 45 16 45 45 16 16 35 35 35 35 45 45 45 35 16 16 16 2 16 16 35 16 2
83
78 52 7 35 33 82 51 27 45 34 17 51 55 25 26 11 52 41 25 41 13 46 33 83 83 7 40 51 33...

output:

51 30 17 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
80 77 74 73 69 68 66 64 61 61 59 56 53 49 47 47 44 42 39 38 36 36 34 33 30 29 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 2...

result:

ok 100 lines

Test #3:

score: 0
Accepted
time: 118ms
memory: 12064kb

input:

1117
72
27 62 37 62 21 71 27 62 37 37 21 21 62 71 27 37 62 37 21 71 27 21 27 71 71 62 71 62 62 37 27 37 71 62 62 37 71 62 71 71 37 27 21 71 21 27 27 62 27 71 62 21 27 37 21 21 71 37 21 37 21 37 27 21 71 62 37 37 62 37 21 27
88
58 48 19 47 46 50 4 78 11 68 80 29 4 3 88 49 54 25 78 47 78 45 34 54 4 46...

output:

63 49 36 23 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
86 84 83 82 81 78 75 72 71 69 65 64 62 60 60 59 57 53 53 52 50 48 46 45 44 42 42 41 40 40 40 40 39 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38...

result:

ok 1117 lines