Submission #915255

# Submission time Handle Problem Language Result Execution time Memory
915255 2024-01-23T15:04:53 Z NValchanov Trampoline (info1cup20_trampoline) C++17
100 / 100
444 ms 46084 KB
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long ll;

const ll MAXN=1e9+10;
const ll MAXK=2e5+10;
const ll MAXQ=2e5+10;
const ll MAXLOG=18;

ll n,m,k,q,mlog;
pair<ll,ll>v[MAXK];
ll lift[MAXK][MAXLOG];
ll depth[MAXK];

void find_mlog()
{
    while((1<<mlog)<=k)
        mlog++;
}

void read()
{
    cin>>n>>m>>k;
    find_mlog();
    for(ll i=1;i<=k;i++)
    {
        ll x,y;
        cin>>x>>y;
        v[i]=make_pair(x,y);
    }
    sort(v+1,v+k+1);
}

ll lift_node(ll node,ll k)
{
    for(ll i=0;i<mlog;i++)
    {
        if(k&(1<<i))
        {
            node=lift[node][i];
        }
    }
    return node;
}

ll bin_search(pair<ll,ll>cur)
{
    ll left=1,right=k,mid;
    while(left<=right)
    {
        mid=left+(right-left)/2;
        if(v[mid]>=cur)
            right=mid-1;
        else
            left=mid+1;
    }
    return right==k?0:right+1;
}

bool check_ans(pair<ll,ll>ans,ll x,ll y)
{
    return ans.first<=x&&ans.second<=y;
}

bool check_query(ll x1,ll y1,ll x2,ll y2)
{
    return x1<=x2&&y1<=y2;
}

void query(ll x1,ll y1,ll x2,ll y2)
{
    if(!check_query(x1,y1,x2,y2))
    {
        cout<<"No"<<endl;
        ///cout<<"hui"<<endl;
        return;
    }
    if(x1==x2)
    {
        cout<<"Yes"<<endl;
        return;
    }
    pair<ll,ll>cur=make_pair(x1,y1);
    ll pos=bin_search(cur);
    pair<ll,ll>ans=v[pos];
    if(!check_ans(ans,x1,y2))
    {
        cout<<"No"<<endl;
        ///cout<<"chep"<<endl;
        return;
    }
    ll diff=x2-x1-1;
    if(depth[pos]<diff)
    {
        cout<<"No"<<endl;
        ///cout<<"daima"<<endl;
        return;
    }
    ll anspos=lift_node(pos,diff);
    if(v[anspos].first<=x2&&v[anspos].second<=y2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

void fill_lift(ll idx,ll pos)
{
    ///cout<<"namereno"<<endl;
    depth[idx]=depth[pos]+1;
    lift[idx][0]=pos;
    for(ll j=1;j<MAXLOG;j++)
        lift[idx][j]=lift[lift[idx][j-1]][j-1];
}

void prekompot()
{
    for(ll i=k;i>0;i--)
    {
        pair<ll,ll>target=v[i];
        target.first++;
        ll pos=bin_search(target);
        ///cout<<pos<<endl;
        ///cout<<v[pos].first<<" "<<v[pos].second<<endl;
        if(v[pos].first==target.first)
            fill_lift(i,pos);
    }
}

void process_queries()
{
    cin>>q;
    for(ll i=1;i<=q;i++)
    {
        ll x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        query(x1,y1,x2,y2);
    }
}

void control_print()
{
    for(ll i=1;i<=k;i++)
    {
        cout<<depth[i]<<" ";
    }
    cout<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

    read();
    prekompot();
    ///control_print();
    process_queries();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5208 KB 200 token(s): yes count is 21, no count is 179
2 Correct 4 ms 5208 KB 200 token(s): yes count is 70, no count is 130
3 Correct 3 ms 5208 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 69 ms 35152 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 69 ms 34928 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 74 ms 34628 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 69 ms 35052 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 175 ms 45684 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 179 ms 45532 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 180 ms 45620 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 179 ms 45600 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 178 ms 45656 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 191 ms 45688 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5464 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 5 ms 5464 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 4 ms 2652 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 5 ms 5468 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 5 ms 5468 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 6 ms 5468 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 375 ms 46084 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 263 ms 45648 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 192 ms 45648 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 367 ms 45604 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 220 ms 45652 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 221 ms 45652 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 234 ms 45732 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 202 ms 45744 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 378 ms 45412 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 342 ms 45652 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 444 ms 45628 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 189 ms 45648 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 202 ms 45748 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 231 ms 45608 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 222 ms 45680 KB 200000 token(s): yes count is 129674, no count is 70326