# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1019701 | beaconmc | Fire (BOI24_fire) | C++14 | 203 ms | 96500 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 idk = i;
ll ans = 0;
FORNEG(j,29,-1){
if (ancc(idk, j) != 1000000000 && (normal[ancc(idk, j)][1] - orig)<=m){
idk = ancc(idk, j);
ans += (1<<j);
}
}
if (normal[idk][1] - orig >= m){
realans = min(realans, ans+1);
}
}
if (realans == 1000000000) cout << -1 << endl;
else cout << realans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |