Submission #1192242

#TimeUsernameProblemLanguageResultExecution timeMemory
1192242AdrianoSterilizing Spray (JOI15_sterilizing)C11
0 / 100
2311 ms1984 KiB
#include <stdio.h>
#include <stdint.h>
#include <math.h>

#define maxN 100001

int max(int a, int b)
{
	return (a < b? b : a);
}


int T[maxN*4];
int Max[maxN*4];
int C[maxN];

int L, R, K;

void Merge(int v)
{
	T[v] = T[v*2] + T[v*2+1];
	Max[v] = max(Max[v*2], Max[v*2+1]);
}

void Build(int v, int tl, int tr)
{
	if( tl == tr )
		T[v] = Max[v] = C[tl];
	else
	{
		int tm = tl + (tr - tl)/2;
		
		Build(v*2,	 	tl,	 	 tm);
		Build(v*2+1,	tm+1,	 tr);
		
		Merge(v);
	}
}

void Push(int v, int tl, int tr) 
{
	if (Max[v] < K) 
	{
		T[v] = 0, Max[v] = 0;
		return;
	}
	  
	if (tl == tr)
	{
		T[v] = Max[v] = round(T[v] / K);
		return;
	}
	  
	int tm = tl + (tr - tl)/2;
	Push(v*2,    	tl, 	tm);
	Push(v*2+1, 	tm+1, 	tr);
	Merge(v);
}

void Update(int U, int v, int tl, int tr)
{
	if( L <= tl && tr <= R)
	{
		if(U >= 0)
		{
			T[v] = Max[v] = U;
		}
		else
			Push(v, tl, tr);
		return;
	}

	if( tr < L || R < tl )
		return;

	int tm = tl + (tr - tl)/2;
		
	Update(U, 	v*2, 	tl, tm);
	Update(U, 	v*2+1, tm+1, tr);
		
	Merge(v);

}

int Query(int v, int tl, int tr)
{
	if( tr < L || R < tl )
		return 0 ;
	
	if( L <= tl && tr <= R )
	{
		return T[v];
	}
	
	int tm = tl + (tr - tl)/2;
	
	return Query(v*2, 	tl, 	tm) +
		Query(v*2+1,	tm+1,	tr);
}

int main(void)
{
	int N, Q; scanf("%d %d %d", &N, &Q, &K);
	for(int i = 0; i < N; i++)
	{
		scanf("%d", &C[i]);
	}
	Build(1, 0, N-1);
	for(int i = 0; i < Q; i++)
	{
		int S, T, U; scanf("%d %d %d", &S, &T, &U);
		
		switch(S)
		{
			case 1:
				L = T-1, R = T-1;
				Update(U, 	1, 0, N-1);
				break;
			case 2:
				L = T-1, R = U-1;
				Update(-1, 	1, 0, N-1);
				break;
			case 3:
				L = T-1, R = U-1;
				printf("%d\n", Query(1, 0, N-1));
				break;
		}
	}
	return 0;
	
}

Compilation message (stderr)

sterilizing.c: In function 'main':
sterilizing.c:103:19: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         int N, Q; scanf("%d %d %d", &N, &Q, &K);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.c:106:17: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |                 scanf("%d", &C[i]);
      |                 ^~~~~~~~~~~~~~~~~~
sterilizing.c:111:30: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |                 int S, T, U; scanf("%d %d %d", &S, &T, &U);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...