Submission #1019707

# Submission time Handle Problem Language Result Execution time Memory
1019707 2024-07-11T07:59:43 Z beaconmc Fire (BOI24_fire) C++14
0 / 100
12 ms 23900 KB
#include <bits/stdc++.h>


typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)

using namespace std;

vector<vector<ll>> normal;
map<ll, ll> maxis;
map<ll,ll> par;

ll anc[100005][30];


ll ancc(ll x, ll k){
	if (x==1000000000) return 1000000000;
	if (anc[x][k] != -1) return anc[x][k];
	if (k==0){
		if (par[x] == x) return anc[x][k] = 1000000000;
		return anc[x][k] = par[x];
	}
	return anc[x][k] = ancc(ancc(x, k-1), k-1);
}

int main(){
	FOR(i,0,100005) FOR(j,0,30) anc[i][j] = -1;
	ll n,m;
	cin >> n >> m;

	FOR(i,0,n){
		ll a,b;
		cin >> a >> b;
		if (a<b) normal.push_back({a,b});
		else normal.push_back({a,m+b});
	}

	sort(normal.begin(), normal.end());
	set<ll> things;

	for (auto&i : normal){
		things.insert(i[0]);
		things.insert(i[1]);
	}
	ll cur = 0;
	ll maxi = -1;
	ll maxting = -1;


	for (auto&i : things){
		while (cur < normal.size()){
			if (normal[cur][0] <= i){
				if (normal[cur][1] > maxi){
					maxi = normal[cur][1];
					maxting = cur;
				}
			}else break;
			cur++;
		}
		maxis[i] = maxting;
	}

	FOR(i,0,normal.size()){
		par[i] = maxis[normal[i][1]];
	}
	ll realans = 1000000000;

	FOR(i,0,normal.size()){
		ll orig = normal[i][0];
		
		ll ans = 0;

		ll lo = 0;
		ll hi = 10000000;


		while (lo < hi){

			ll mid = (lo+hi)/2;
			ll idk = i;
			FOR(j,0,30){
				if (mid&(1<<j)){
					idk = ancc(idk, j);
				}
			}
			if (idk == 1000000000 || normal[idk][1] - orig >= m){
				hi = mid;
			}else{
				lo = mid+1;
			}
		}
		if (lo < 1000000) realans = min(realans, lo+1);
		



		


	}
	if (realans == 1000000000) cout << -1 << endl;
	else cout << realans << endl;








}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:52:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   while (cur < normal.size()){
      |          ~~~~^~~~~~~~~~~~~~~
Main.cpp:5:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   64 |  FOR(i,0,normal.size()){
      |      ~~~~~~~~~~~~~~~~~           
Main.cpp:64:2: note: in expansion of macro 'FOR'
   64 |  FOR(i,0,normal.size()){
      |  ^~~
Main.cpp:5:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   69 |  FOR(i,0,normal.size()){
      |      ~~~~~~~~~~~~~~~~~           
Main.cpp:69:2: note: in expansion of macro 'FOR'
   69 |  FOR(i,0,normal.size()){
      |  ^~~
Main.cpp:72:6: warning: unused variable 'ans' [-Wunused-variable]
   72 |   ll ans = 0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -