Submission #111786

#TimeUsernameProblemLanguageResultExecution timeMemory
111786AMO5Two Antennas (JOI19_antennas)C++98
2 / 100
3071 ms267912 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

ll n,h,a,b,q,lft,rgt;
ll hgt[200222];
pll rng[200222];
vll adj[200222];

int check(int i, int j)
{
	
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    cin >> n;
    for(ll i=0; i<n; i++){
		cin >> h >> a >> b;
		hgt[i] = h;
		//left
		for(ll j=a; j<=b; j++){
			if(i-j>=0){
				adj[i-j].pb(i);
			}
			else break;
		}
		//right
		for(ll j=a; j<=b; j++){
			if(i+j<n){
				adj[i+j].pb(i);
			}
			else break;
		}
	}
	/*
	cout << " *** " << endl;
	for(int i=0; i<n; i++){
		for(int j=0; j<adj[i].size(); j++){
			cout << adj[i][j] << " " ;
		}
		cout << endl;
	}
	cout << " *** " << endl;
	*/
	cin >> q;
	for(ll i=0; i<q; i++){
		ll ans = -1;
		cin >> lft >> rgt;
		lft--; rgt--;
		for(ll j=lft; j<=rgt; j++){
			for(ll k=j+1; k<=rgt; k++){
				
				if(binary_search(adj[j].begin(),adj[j].end(),k)&&binary_search(adj[k].begin(),adj[k].end(),j)){
					ans = max(ans, abs(hgt[j]-hgt[k]));
					//cout << j << " " << k <<  " " << hgt[j]-hgt[k] << endl;
				}
			}
		}
		cout << ans << endl;
	}
}	

Compilation message (stderr)

antennas.cpp: In function 'int check(int, int)':
antennas.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...