Submission #61592915


Source Code Expand

Copy
#include <bits/stdc++.h>
#define int long long
//#define USE_FREOPEN
//#define MUL_TEST
#define FILENAME ""
using namespace std;
struct Seg
{
int l,r,sum,laz;
#define l(p) tr[p].l
#define r(p) tr[p].r
#define sum(p) tr[p].sum
#define laz(p) tr[p].laz
}tr[2500005];
int a[500005];
void pushup(int p)
{
sum(p) = sum(p << 1) + sum(p << 1 | 1);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
#define int long long
//#define USE_FREOPEN
//#define MUL_TEST
#define FILENAME ""
using namespace std;

struct Seg
{
	int l,r,sum,laz;
	#define l(p) tr[p].l
	#define r(p) tr[p].r
	#define sum(p) tr[p].sum
	#define laz(p) tr[p].laz
}tr[2500005];

int a[500005];

void pushup(int p)
{
	sum(p) = sum(p << 1) + sum(p << 1 | 1);
}

void pushdown(int p) 
{
	if (laz(p))
	{
		laz(p << 1) += laz(p);
		laz(p << 1 | 1) += laz(p);
		sum(p << 1) += laz(p) * (r(p << 1) - l(p << 1) + 1);
		sum(p << 1 | 1) += laz(p) * (r(p << 1 | 1) - l(p << 1 | 1) + 1);
		laz(p) = 0;
	}
}

void build(int p,int l,int r)
{
	l(p) = l,r(p) = r,laz(p) = 0;
	if (l == r)
	{
		sum(p) = a[l];
		return;
	}
	int mid = l + r >> 1;
	build(p << 1,l,mid);
	build(p << 1 | 1,mid + 1,r);
	pushup(p); 
}

void update(int p,int l,int r,int x)
{
	if (l(p) >= l && r(p) <= r)
	{
		sum(p) += x * (r(p) - l(p) + 1);
		laz(p) += x; 
		return;
	}
	pushdown(p);
	int mid = l(p) + r(p) >> 1;
	if (mid >= l) update(p << 1,l,r,x);
	if (mid < r) update(p << 1 | 1,l,r,x);
	pushup(p);
}

int query(int p,int l,int r)
{
	if (l(p) >= l && r(p) <= r) return sum(p);
	pushdown(p);
	int mid = l(p) + r(p) >> 1;
	int sum = 0;
	if (mid >= l) sum += query(p << 1,l,r);
	if (mid < r) sum += query(p << 1 | 1,l,r);
	return sum;
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	build(1,1,n);
	for (int i = 1; i < n; i++)
	{
		int gv = min(query(1,i,i),n - i);
		update(1,i + 1,i + gv,1);
		update(1,i,i,-gv);
		printf("%lld ",query(1,i,i));
	}
	printf("%lld\n",query(1,n,n));
}

signed main()
{
	#ifdef USE_FREOPEN
		freopen(FILENAME ".in","r",stdin);
		freopen(FILENAME ".out","w",stdout);
	#endif
	int _ = 1;
	#ifdef MUL_TEST
		cin >> _;
	#endif
	while (_--)
		solve();
	_^=_;
	return 0^_^0;
}

Submission Info

Submission Time
Task D - Coming of Age Celebration
User Hyh12377
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1897 Byte
Status AC
Exec Time 439 ms
Memory 40592 KB

Compile Error

Main.cpp: In function ‘void build(long long int, long long int, long long int)’:
Main.cpp:44:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   44 |         int mid = l + r >> 1;
      |                   ~~^~~
Main.cpp: In function ‘void update(long long int, long long int, long long int, long long int)’:
Main.cpp:59:24: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   59 |         int mid = l(p) + r(p) >> 1;
      |                        ^
Main.cpp: In function ‘long long int query(long long int, long long int, long long int)’:
Main.cpp:69:24: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   69 |         int mid = l(p) + r(p) >> 1;
      |                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt
Case Name Status Exec Time Memory
sample00.txt AC 1 ms 3676 KB
sample01.txt AC 1 ms 3604 KB
sample02.txt AC 1 ms 3604 KB
testcase00.txt AC 1 ms 3584 KB
testcase01.txt AC 307 ms 40396 KB
testcase02.txt AC 375 ms 40592 KB
testcase03.txt AC 352 ms 39672 KB
testcase04.txt AC 439 ms 40396 KB
testcase05.txt AC 100 ms 20948 KB
testcase06.txt AC 439 ms 40464 KB
testcase07.txt AC 337 ms 39692 KB
testcase08.txt AC 438 ms 40424 KB
testcase09.txt AC 355 ms 39768 KB
testcase10.txt AC 437 ms 40300 KB
testcase11.txt AC 153 ms 21632 KB
testcase12.txt AC 438 ms 40532 KB
testcase13.txt AC 257 ms 39012 KB
testcase14.txt AC 436 ms 40416 KB
testcase15.txt AC 39 ms 8172 KB
testcase16.txt AC 438 ms 40256 KB
testcase17.txt AC 354 ms 39604 KB
testcase18.txt AC 300 ms 40060 KB
testcase19.txt AC 285 ms 40172 KB


2025-04-04 (Fri)
03:07:27 +00:00