Submission #1078693

# Submission time Handle Problem Language Result Execution time Memory
1078693 2024-08-28T04:31:05 Z arashMLG Fire (BOI24_fire) C++17
0 / 100
1 ms 604 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...)    69
#define debugArr(...)  69
#endif
using namespace std;

typedef long long     ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;

const int N = 4e5 + 23;
const int LOG = 20;
const ll inf = 1e18;

#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)

int n,m;
vector<pii> edges;
int up[LOG][N];


int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>m;
	for(int i = 1; i <= n ; i ++) {
		int l,r; cin>>l>>r;
		if(l <= r) {
			edges.pb({l,r});
			edges.pb({l+m,r+m});
		} else {
			edges.pb({l,r+m});
		}
	}
	sort(all(edges));
	set<pii> st;
	int R = sz(edges)-1;
	for(int i = sz(edges)-1; i >= 0; i --) {
		while(R > i && edges[R].F > edges[i].S) {
			st.erase({edges[R].S,R});
			R --;	
		}
		if(sz(st)) up[0][i] = st.rbegin()->S;
		else       up[0][i] = i;

		for(int j = 1; j < LOG; j ++) up[j][i] = up[j-1][up[j-1][i]];
		st.insert({edges[i].S,i});
	}
	int ans = N + 23;
	for(int i = 0;i < sz(edges); i ++) {
		int l = edges[i].F;
		if(edges[up[LOG-1][i]].S - l < m) continue;
		int mn = 1,v= i;
		for(int j = LOG-1; j >= 0 ; j --) {
			if(edges[up[j][v]].S - l < m) {
				mn += (1 << j);
				v = up[j][i];
			}
		}
		ans=  min(ans,mn + 1);
	}
	cout<<(ans == N+ 23 ? -1 : ans) << '\n';	
	return 0;
}

// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Incorrect 0 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -