Submission #209581

# Submission time Handle Problem Language Result Execution time Memory
209581 2020-03-14T17:38:11 Z Lawliet Boat (APIO16_boat) C++14
0 / 100
1185 ms 524292 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

const int MAXN = 510;
const int MAXV = 1000000000;
const int MOD = 1000000007;

class SparseSegmentTree
{
	public:

		void create()
		{
			e.push_back( 0 );
			d.push_back( 0 );
			sum.push_back( 0 );
		}

		int getLeft(int node)
		{
			if( e[node] == 0 )
			{
				e[node] = ++cntNode;
				create();
			}

			return e[node];
		}

		int getRight(int node)
		{
			if( d[node] == 0 )
			{
				d[node] = ++cntNode;
				create();
			}

			return d[node];
		}

		void update(int node, int l, int r, int i, int v)
		{
			if( i < l || r < i ) return;

			if( l == r )
			{
				sum[node] += v;
				sum[node] %= MOD;

				return;
			}

			int m = ( l + r )/2;

			if( i <= m ) update( getLeft(node) , l , m , i , v );
			else update( getRight(node) , m + 1 , r , i , v );

			sum[node] = sum[ e[node] ] + sum[ d[node] ];
		}

		int query(int node, int l, int r, int i, int j)
		{
			if( node == 0 ) return 0;
			if( j < l || r < i ) return 0;
			if( i <= l && r <= j ) return sum[node];

			int m = ( l + r )/2;

			int sumLeft = query( e[node] , l , m , i , j );
			int sumRight = query( d[node] , m + 1 , r , i , j );

			return ( sumLeft + sumRight )%MOD;
		}

		SparseSegmentTree() : cntNode(1) { create(); create(); }

	private:

		int cntNode;

		vector< int > e, d;
		vector< int > sum;
};

int n;

SparseSegmentTree SEG;

int main()
{
	scanf("%d",&n);

	SEG.update( 1 , 0 , MAXV , 0 , 1 );

	for(int i = 1 ; i <= n ; i++)
	{
		int l, r;
		scanf("%d %d",&l,&r);

		vector< int > aux;

		for(int j = l ; j <= r ; j++)
			aux.push_back( SEG.query( 1 , 0 , MAXV , 0 , j - 1 ) );

		for(int j = 0 ; j < aux.size() ; j++)
			SEG.update( 1 , 0 , MAXV , j + l , aux[j] );
	}

	printf("%d\n",SEG.query( 1 , 0 , MAXV , 1 , MAXV ));
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:107:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0 ; j < aux.size() ; j++)
                   ~~^~~~~~~~~~~~
boat.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
boat.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&l,&r);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1185 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -