QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222964#7616. Jump Graphucup-team191#WA 3ms34408kbC++142.2kb2023-10-21 20:10:542023-10-21 20:10:54

Judging History

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

  • [2023-10-21 20:10:54]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:34408kb
  • [2023-10-21 20:10:54]
  • 提交

answer

#include <cstdio>

using namespace std;

const int N = 3e5 + 500;
const int OFF = (1 << 19);

typedef long long ll;

ll Lmax[2 * OFF], Rmax[2 * OFF];
ll Lprop[2 * OFF], Rprop[2 * OFF];
ll *T, *prop;
int p[N], n;

void refresh(int x, int len) {
	T[x] += prop[x] * len;
	if(x < OFF) {
		prop[2 * x] += prop[x];
		prop[2 * x + 1] += prop[x];
	}
	prop[x] = 0;
}

void update(int i, int a, int b, int lo, int hi, int x) {
	if(lo <= a && b <= hi) {
		prop[i] += x; refresh(i, b - a + 1); return;
	}	
	refresh(i, b - a + 1);
	if(a > hi || b < lo) return;
	update(2 * i, a, (a + b) / 2, lo, hi, x);
	update(2 * i + 1, (a + b) / 2 + 1, b, lo, hi, x);
	T[i] = T[2 * i] + T[2 * i + 1];
}

int mrg(int i, int j) {
	return p[i] > p[j] ? i : j;
}

int Tmax[2 * OFF];

ll query(int i, int a, int b, int lo, int hi) {
	refresh(i, b - a + 1);
	if(lo <= a && b <= hi) return T[i];
	if(a > hi || b < lo) return 0;
	return query(2 * i, a, (a + b) / 2, lo, hi) + 
		   query(2 * i + 1, (a + b) / 2 + 1, b, lo, hi);
}

int get_max(int i, int a, int b, int lo, int hi) {
	if(lo <= a && b <= hi) return Tmax[i];
	if(a > hi || b < lo) return n;
	return mrg(get_max(2 * i, a, (a + b) / 2, lo, hi), get_max(2 * i + 1, (a + b) / 2 + 1, b, lo, hi));
}


ll l_dis[N], r_dis[N], ans[N];

void dfs(int l, int r, ll ohl, ll ohr) {
	if(r < l) return;
	int mid = get_max(1, 0, OFF - 1, l, r);
	ans[mid] = l_dis[mid] + r_dis[mid] + ohl + ohr;
	dfs(mid + 1, r, ohl + r_dis[mid] + (mid - l + 1), ohr);
	dfs(l, mid - 1, ohl, ohr + (r - mid + 1) + l_dis[mid]);
}

void solve(int l, int r){
	if(r < l) return;
	int mid = get_max(1, 0, OFF - 1, l, r);
	solve(l, mid - 1); solve(mid + 1, r);	
	T = Lmax, prop = Lprop;
	l_dis[mid] = query(1, 0, OFF - 1, mid + 1, r);
	update(1, 0, OFF - 1, mid, r, 1);

	T = Rmax, prop = Rprop;
	r_dis[mid] = query(1, 0, OFF - 1, l, mid - 1);
	update(1, 0, OFF - 1, l, mid, 1);	
}

int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++) scanf("%d", p + i), Tmax[OFF + i] = i;
	for(int i = OFF - 1; i ; i--) Tmax[i] = mrg(Tmax[2 * i], Tmax[2 * i + 1]);
	solve(0, n - 1); 
	dfs(0, n - 1, 0, 0);
	for(int i = 0;i < n;i++) printf("%lld ", ans[i]);
	printf("\n"); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 32364kb

input:

6
1 6 3 2 5 4

output:

11 7 7 7 6 8 

result:

ok single line: '11 7 7 7 6 8 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 34320kb

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 34408kb

input:

36
9 29 1 3 14 31 24 21 10 18 22 16 8 7 15 12 17 19 25 28 27 34 11 6 32 4 20 13 2 35 23 26 33 36 30 5

output:

101 98 99 99 100 87 81 79 79 79 73 72 71 71 70 72 72 77 83 94 107 100 120 120 116 118 116 116 116 113 142 142 143 143 175 175 

result:

wrong answer 1st lines differ - expected: '92 89 90 90 91 78 73 71 71 71 ...110 107 136 136 137 136 168 168', found: '101 98 99 99 100 87 81 79 79 7...16 113 142 142 143 143 175 175 '