Submission #514681

# Submission time Handle Problem Language Result Execution time Memory
514681 2022-01-18T10:55:02 Z Theo830 Trampoline (info1cup20_trampoline) C++17
0 / 100
1386 ms 97760 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll an[200005][20];
ll depth[200005];
vector<vll>adj;
void build(ll s,ll p){
    an[s][0] = p;
    f(i,1,20){
        an[s][i] = an[an[s][i-1]][i-1];
    }
    for(auto x:adj[s]){
        if(x != p){
            depth[x] = depth[s] + 1;
            build(x,s);
        }
    }
}
ll kth(ll x,ll k){
    ll ans = x;
    if(depth[x] < k){
        return 0;
    }
    ll pos = 0;
    while(k > 0){
        if(k % 2){
            ans = an[ans][pos];
        }
        pos++;
        k /= 2;
    }
    return ans;
}
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll r,c;
    cin>>r>>c;
    map<ll,ll>mp;
    set<ll>ex;
    ll n;
    cin>>n;
    ll a[n+1],b[n+1];
    adj.assign(200005,vll());
    f(i,0,n){
        cin>>a[i]>>b[i];
        ex.insert(a[i]);
    }
    n++;
    ex.insert(r);
    a[n-1] = r;
    b[n-1] = c;
    ll pos = 0;
    for(auto x:ex){
        mp[x] = pos;
        pos++;
    }
    set<ll> exo[(ll)ex.size() + 5];
    ii sim[200005];
    map<ii,ll>M;
    pos = 1;
    f(i,0,n){
        exo[mp[a[i]]].insert(b[i]);
        sim[pos] = ii(a[i],b[i]);
        M[ii(a[i],b[i])] = pos;
        pos++;
    }
    ll p = 0;
    for(auto x:ex){
        for(auto y:exo[p]){
            if(!ex.count(x+1)){
                adj[0].pb(M[ii(x,y)]);
                adj[M[ii(x,y)]].pb(0);
            }
            auto it = exo[p+1].lower_bound(y);
            if(it == exo[p+1].end()){
                adj[0].pb(M[ii(x,y)]);
                adj[M[ii(x,y)]].pb(0);
            }
            else{
                adj[M[ii(x+1,(*it))]].pb(M[ii(x,y)]);
                adj[M[ii(x,y)]].pb(M[ii(x+1,(*it))]);
            }
        }
        p++;
    }
    build(0,0);
    ll t;
    cin>>t;
    while(t--){
        ll xa,ya,xb,yb;
        cin>>xa>>ya>>xb>>yb;
        bool ok = 1;
        if(xa > xb || ya > yb){
            ok = 0;
        }
        auto it = exo[mp[xa]].lower_bound(ya);
        if(xa != xb){
            if(!ex.count(xa) || it == exo[mp[xa]].end()){
                ok = 0;
            }
            else{
                ll v = kth(M[ii(xa,(*it))],xb - xa);
                if(v == 0 || sim[v].S > yb){
                    ok = 0;
                }
            }
        }
        if(ok){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 10956 KB expected YES, found NO [68th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 471 ms 73848 KB expected YES, found NO [1822nd token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 708 ms 74940 KB expected YES, found NO [4th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 9752 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1386 ms 97760 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -