提出 #66127842


ソースコード 拡げる

#include <iostream>
#include <stack>
using namespace std;
#define LL long long
#define MaxN 200005
LL n, a[MaxN], l[MaxN], r[MaxN], tr[MaxN];
stack <int> s;

int lowbit(int x) {
	return x & -x;
}
void add(int x, int k) {
	while (x <= n) {
		tr[x] += k;
		x += lowbit(x);
	}
}
LL calc(int x) {
	LL re = 0;
	while (x > 0) {
		re += tr[x];
		x -= lowbit(x);
	}
	return re;
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) {
		while (!s.empty() && a[i] > a[s.top()]) s.pop();
		if (s.empty()) l[i] = i-1;
		else l[i] = i-s.top()-1;
		s.push(i);
	}

	while(!s.empty()) s.pop();
	for(int i = n; i >= 1; i--) {
		while (!s.empty() && a[i] >= a[s.top()]) s.pop();
		if (s.empty()) r[i] = n-i;
		else r[i] = s.top()-i-1;
		s.push(i);
	}


	for(int i = 1; i <= n; i++) {
		int w = min(l[i], r[i]);
		for(int j = 1; j <= w+1; j++) add(j, a[i]);
		for(int j = l[i]+r[i]-w+2; j <= l[i]+r[i]+2; j++) add(j, -a[i]);
	}

	for(int i = 1; i <= n; i++) {
		cout << calc(i) << endl;
	}
	return 0;
}

提出情報

提出日時
問題 F - Sums of Sliding Window Maximum
ユーザ gobywind
言語 C++ 20 (gcc 12.2)
得点 550
コード長 1083 Byte
結果 AC
実行時間 275 ms
メモリ 10644 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 550 / 550
結果
AC × 3
AC × 37
セット名 テストケース
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-small-01.txt, 01-small-02.txt, 01-small-03.txt, 01-small-04.txt, 01-small-05.txt, 01-small-06.txt, 01-small-07.txt, 01-small-08.txt, 01-small-09.txt, 01-small-10.txt, 01-small-11.txt, 01-small-12.txt, 01-small-13.txt, 01-small-14.txt, 01-small-15.txt, 01-small-16.txt, 01-small-17.txt, 01-small-18.txt, 01-small-19.txt, 01-small-20.txt, 01-small-21.txt, 01-small-22.txt, 01-small-23.txt, 01-small-24.txt, 02-large-01.txt, 02-large-02.txt, 02-large-03.txt, 02-large-04.txt, 02-large-05.txt, 02-large-06.txt, 02-large-07.txt, 02-large-08.txt, 02-large-09.txt, 02-large-10.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 1 ms 3416 KiB
00-sample-02.txt AC 1 ms 3448 KiB
00-sample-03.txt AC 1 ms 3428 KiB
01-small-01.txt AC 1 ms 3460 KiB
01-small-02.txt AC 1 ms 3456 KiB
01-small-03.txt AC 1 ms 3456 KiB
01-small-04.txt AC 1 ms 3380 KiB
01-small-05.txt AC 1 ms 3424 KiB
01-small-06.txt AC 1 ms 3628 KiB
01-small-07.txt AC 1 ms 3480 KiB
01-small-08.txt AC 1 ms 3456 KiB
01-small-09.txt AC 1 ms 3428 KiB
01-small-10.txt AC 1 ms 3420 KiB
01-small-11.txt AC 1 ms 3448 KiB
01-small-12.txt AC 1 ms 3460 KiB
01-small-13.txt AC 1 ms 3620 KiB
01-small-14.txt AC 1 ms 3464 KiB
01-small-15.txt AC 3 ms 3492 KiB
01-small-16.txt AC 3 ms 3684 KiB
01-small-17.txt AC 3 ms 3532 KiB
01-small-18.txt AC 3 ms 3516 KiB
01-small-19.txt AC 3 ms 3500 KiB
01-small-20.txt AC 3 ms 3572 KiB
01-small-21.txt AC 4 ms 3692 KiB
01-small-22.txt AC 3 ms 3468 KiB
01-small-23.txt AC 4 ms 3488 KiB
01-small-24.txt AC 3 ms 3544 KiB
02-large-01.txt AC 243 ms 10504 KiB
02-large-02.txt AC 267 ms 9604 KiB
02-large-03.txt AC 212 ms 10644 KiB
02-large-04.txt AC 256 ms 9804 KiB
02-large-05.txt AC 250 ms 9832 KiB
02-large-06.txt AC 275 ms 9740 KiB
02-large-07.txt AC 275 ms 9744 KiB
02-large-08.txt AC 263 ms 9696 KiB
02-large-09.txt AC 240 ms 10100 KiB
02-large-10.txt AC 247 ms 9808 KiB