제출 #675294

#제출 시각아이디문제언어결과실행 시간메모리
675294Tuanlinh123Trampoline (info1cup20_trampoline)C++17
100 / 100
444 ms35712 KiB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

#define LOCALIO "C:/Users/admin/Documents/Code/"

vector <pll> tram;
ll to[200005][20];

void answer(ll a)
{
    if (a) cout << "Yes\n";
    else cout << "No\n";
}

int main()
{
    #ifdef LOCAL
        freopen( LOCALIO "input.txt","r",stdin) ;
        freopen( LOCALIO "output.txt","w",stdout) ;
    #endif

    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
//	freopen("FIBONACCI.inp","r",stdin);
//	freopen("FIBONACCI.out","w",stdout);
    ll R, C, n; cin >> R >> C >> n;
    for (ll i=1; i<=n; i++)
    {
        ll r, c; cin >> r >> c;
        tram.pb({r, c});
    }
    sort(tram.begin(), tram.end());
    for (ll i=0; i<n; i++)
    {
        ll r=tram[i].fi, c=tram[i].se;
        auto ptr=lower_bound(tram.begin(), tram.end(), mp(r+1, c));
        if (ptr==tram.end())
        {
            to[i][0]=-1;
            continue;
        }
        pll ptr1=*ptr; ll r1=ptr1.fi, c1=ptr1.se;
        if (r1!=r+1)
        {
            to[i][0]=-1;
            continue;
        }
        to[i][0]=ptr-tram.begin();
    }
    // for (ll i=0; i<n; i++)
    //     cout << i << " " << to[i][0] << "\n";
    for (ll l=1; l<20; l++)
    {
        for (ll i=0; i<n; i++)
        {
            ll t=to[i][l-1];
            if (t==-1)
            {
                to[i][l]=-1;
                continue;
            }
            to[i][l]=to[t][l-1];
        }
    }
    ll t; cin >> t;
    while(t--)
    {
        ll xa, ya, xb, yb;
        cin>>xa>>ya>>xb>>yb;
        if (xa==xb)
        {
            answer(yb>=ya);
            continue;
        }
        ll jump=xb-xa-1, f=lower_bound(tram.begin(), tram.end(), mp(xa, ya))-tram.begin(), bit=0;
        if (f>=tram.size() || tram[f].fi!=xa)
        {
            answer(0);
            continue;
        }
        while (f!=-1 && jump)
        {
            if (jump&1)
                f=to[f][bit];
            bit++; jump>>=1;
        }
        if (f==-1 || tram[f].se>yb)
            answer(0);
        else answer(1);
    }
}

컴파일 시 표준 에러 (stderr) 메시지

trampoline.cpp: In function 'int main()':
trampoline.cpp:49:39: warning: unused variable 'c1' [-Wunused-variable]
   49 |         pll ptr1=*ptr; ll r1=ptr1.fi, c1=ptr1.se;
      |                                       ^~
trampoline.cpp:83:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         if (f>=tram.size() || tram[f].fi!=xa)
      |             ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...