Submission #813784

# Submission time Handle Problem Language Result Execution time Memory
813784 2023-08-08T03:43:52 Z LIF Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 3044 KB
#include "towers.h"
#include <vector>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
int n;
pair <int,int> aa[300005];
int b[300005];
int rightD[300005];
int leftD[300005];
void init(int N, std::vector<int> H)
{
	n = N;
	for(int i=0;i<H.size();i++)
	{
		aa[i+1].first = H[i];
		aa[i+1].second = i+1;
		b[i+1] = H[i];
	}
	sort(aa+1,aa+n+1);
	for(int i=N;i>=1;i--)
	{
		rightD[i] = N+1;
		leftD[i] = 0;
	}
	return;
}
int lowbit(int x)
{
	return x & (-x);
}
int su[300005];
void change(int x,int add)
{
	while(x <= n)
	{
		su[x] += add;
		x += lowbit(x);				
	}
}
int query(int x)
{
	int ans = 0;
	while(x > 0)
	{
		ans += su[x];
		x -= lowbit(x);
	}
	return ans;
}
int ask(int l,int r)
{
	return query(r) - query(l-1);
}
int max_towers(int L, int R, int D)
{
	L += 1;R += 1;
	stack<int> s;
	b[0] = 0;
	b[n+1] = 0;
	//for(int i=1;i<=n;i++)cout<<b[i]<<" ";
	//cout<<endl;
	s.push(n+1);
	for(int i=n;i>=1;i--)
	{
		while(s.empty() ==false && b[i] >= b[s.top()])s.pop();
		if(s.empty() == false && b[i] <= b[s.top()] - D)rightD[i] = s.top();
		s.push(i);
	//	cout<<s.top()<<endl;
	}
	//cout<<endl;
	while(s.empty() == false)s.pop();
	s.push(0);
	for(int i=1;i<=n;i++)
	{
		while(s.empty() == false && b[i] >= b[s.top()])s.pop();
		if(s.empty() == false && b[i] <= b[s.top()] - D)leftD[i] = s.top();
		s.push(i);
	//	cout<<s.top()<<" ";
	}
	//cout<<endl;
	/*for(int i=1;i<=n;i++)
	{
		cout<<leftD[i]<<" "<<rightD[i]<<endl;
	}*/
	int ans = 0;
	for(int now=1;now<=n;now++)
	{
		int i = aa[now].second;
		if(i < L || i > R)continue;
	//	cout<<i<<" ";
		//if(leftD[i] < L || rightD[i] > R)continue;
		if(ask(leftD[i],i) <= 0 && ask(i,rightD[i]) <= 0)
		{
			//cout<<i<<endl;
			change(i,1);
			ans++;
		}
	}
 	return ans;
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<H.size();i++)
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4014 ms 1944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '292', found: '271'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '292', found: '271'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4081 ms 3044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '292', found: '271'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4014 ms 1944 KB Time limit exceeded
2 Halted 0 ms 0 KB -