Submission #1433620


Source Code Expand

#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long LL;

const int maxn = 1000009;
int a[maxn], x[maxn];
LL s1[maxn], s2[maxn], pre, res;
int n, m, cnt, last;

inline int read(){
	char ch = getchar(); int x = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9') { x = x*10 + ch-'0'; ch = getchar(); }
	return x;
}

int del(){
	int m = 0;
	for (int i=1; i<=n; i++)
		if (i == 1 || x[i] != x[m]) x[++m] = x[i];
	return m;
}

int search(int k){
	int l = 1, r = m, mid;
	while (l < r){
		mid = (l+r) >> 1;
		if (k <= x[mid]) r = mid;
		else l = mid+1;
	}
	return l;
}

void update(LL s[], int x, int y){
	for (; x<=m; x+=lowbit(x)) s[x] += y;
}

LL query(LL s[], int x){
	LL res = 0; for (; x; x-=lowbit(x)) res += s[x]; return res;
}

int main(){
	n = read();
	for (int i=1; i<=n; i++)
		x[i] = a[i] = read();
	sort(x+1, x+n+1); m = del();
	for (int i=1; i<=n; i++){
		a[i] = search(a[i]);
		update(s1, a[i], 1);
		update(s2, a[i], x[a[i]]);
	}
	pre = last = 0;
	for (int i=1; i<=n; i++)
		if (a[last] < a[i]){
			res = query(s2, a[i]) + 1LL*(n-query(s1, a[i]))*x[a[i]];
			printf("%lld\n", res-pre);
			last = i; pre = res;
		}
		else puts("0");
	return 0;
}

Submission Info

Submission Time
Task E - Frequency
User Cyanic
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1285 Byte
Status AC
Exec Time 30 ms
Memory 10112 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 39
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
All 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 2 ms 6400 KB
00_example_02.txt AC 2 ms 6400 KB
01.txt AC 2 ms 6400 KB
02.txt AC 4 ms 6400 KB
03.txt AC 2 ms 6400 KB
04.txt AC 2 ms 6400 KB
05.txt AC 2 ms 6400 KB
06.txt AC 2 ms 6400 KB
07.txt AC 2 ms 6400 KB
08.txt AC 2 ms 6400 KB
09.txt AC 4 ms 6400 KB
10.txt AC 2 ms 6400 KB
11.txt AC 28 ms 9088 KB
12.txt AC 28 ms 9088 KB
13.txt AC 28 ms 9088 KB
14.txt AC 28 ms 9088 KB
15.txt AC 28 ms 9088 KB
16.txt AC 14 ms 6528 KB
17.txt AC 30 ms 9728 KB
18.txt AC 21 ms 9344 KB
19.txt AC 8 ms 6528 KB
20.txt AC 24 ms 6912 KB
21.txt AC 2 ms 6400 KB
22.txt AC 2 ms 6400 KB
23.txt AC 2 ms 6400 KB
24.txt AC 4 ms 6528 KB
25.txt AC 2 ms 6400 KB
26.txt AC 2 ms 6400 KB
27.txt AC 2 ms 6400 KB
28.txt AC 29 ms 9984 KB
29.txt AC 30 ms 9984 KB
30.txt AC 30 ms 10112 KB
31.txt AC 29 ms 9984 KB
32.txt AC 30 ms 9984 KB
33.txt AC 20 ms 9344 KB
34.txt AC 20 ms 9344 KB
35.txt AC 20 ms 9344 KB
36.txt AC 21 ms 9344 KB
37.txt AC 20 ms 9344 KB