Submission #675378

# Submission time Handle Problem Language Result Execution time Memory
675378 2022-12-27T07:18:16 Z vjudge1 Trampoline (info1cup20_trampoline) C++17
100 / 100
1345 ms 88684 KB
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma,sse4.2")
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define ii __int128
#define ld long double
#define cd complex<ld>
#define pll pair<int,int>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll r, c, n, cur, q;
vector<pll> pt;
vector<ll> nen;
map<ll,ll> M;
vector<pll> L[400005];
vector<ll> T[200005];
ll bin[21][200005];
void dfs(ll v,ll par)
{
    bin[0][v] = par;
    for(int i = 1;i <= 20; i++)
    {
        ll x = bin[i-1][v];
        bin[i][v] = bin[i-1][x];
    }
    for(auto u: T[v])
    {
        if(u==par) continue;
        dfs(u, v);
    }
}
void solve()
{
    cin >> r >> c >> n;
    for(int i = 1; i<=n ; i++)
    {
        ll a, b;
        cin >> a >> b;
        pt.push_back(mp(a,b));
        //pt.push_back(mp(a+1,b));
        nen.push_back(a);
        nen.push_back(a+1);
    }
    sort(nen.begin(),nen.end());
    cur = 1;
    M[nen[0]] = 1;
    for(int i = 1; i< nen.size(); i++)
    {
        if(nen[i]!=nen[i-1]) cur++;
        M[nen[i]] = cur;
    }
    for(int i = 0; i<n ;i++)
    {
        //cout << pt[i].fi << " ";
        pt[i].fi = M[pt[i].fi];
        //cout << pt[i].fi << "\n";
        L[pt[i].fi].push_back(mp(pt[i].se, i+1));
    }
    for(int i = 400000; i>= 1; i--)
    {
        sort(L[i].begin(),L[i].end());
        ll sz = L[i].size();
        for(int j = 0;j < sz; j++)
        {
            //cout << i << " " << j << "\n";
            if(j==sz-1)
            {
                vector<pll>::iterator it = lower_bound(L[i+1].begin(),L[i+1].end(),mp(L[i][j].fi, 0ll));
                //cout << -1;
                //cout << "-1";
                if(it==L[i+1].end())
                {
                    T[L[i][j].se].push_back(0);
                    T[0].push_back(L[i][j].se);
                }
                else
                {
                    pll a = *it;
                    T[L[i][j].se].push_back(a.se);
                    T[a.se].push_back(L[i][j].se);
                }
                //cout << -1;
            }
            else
            {
                vector<pll>::iterator it = lower_bound(L[i+1].begin(),L[i+1].end(),mp(L[i][j].fi, 0ll));
                if(it==L[i+1].end())
                {
                    T[L[i][j].se].push_back(L[i][j+1].se);
                    T[L[i][j+1].se].push_back(L[i][j].se);
                }
                else
                {
                    pll a = *it;
                    if(L[i][j+1].fi<=a.fi)
                    {
                        T[L[i][j].se].push_back(L[i][j+1].se);
                        T[L[i][j+1].se].push_back(L[i][j].se);
                    }
                    else
                    {
                        T[L[i][j].se].push_back(a.se);
                        T[a.se].push_back(L[i][j].se);
                    }
                }
            }
        }
    }
    dfs(0, 0);
    cin >> q;
    for(int xx = 1; xx <= q; xx++)
    {
        ll a, b, u, v;
        cin >> a >> b >> u >> v;
        if(a==u&&b<=v)
        {
            cout << "Yes\n";
            continue;
        }
        else if(a==u)
        {
            cout << "No\n";
            continue;
        }
        a = M[a];
        u = M[u];
        if(u==0)
        {
            cout << "No\n";
            continue;
        }
        vector<pll>::iterator it = lower_bound(L[a].begin(),L[a].end(),mp(b,0ll));
        if(it==L[a].end())
        {
            cout << "No\n";
            continue;
        }
        pll p = *it;
        ll x = p.se;
        //cout << x << " " << u << '\n';
        for(int i = 20; i>=0 ; i--)
        {
            if(bin[i][x]==0||pt[bin[i][x]-1].fi>=u-1) continue;
            //cout << x << " " << i << " " << pt[bin[i][x]-1].fi << "\n";
            x = bin[i][x];
        }
        //cout << pt[x-1].fi << "\n";
        while(x!=0&&pt[x-1].fi<u-1) x = bin[0][x];
        if(pt[x-1].fi!=u-1)
        {
            cout << "No\n";
            continue;
        }
        else if(x==0)
        {
            cout << "No\n";
        }
        else
        {
            if(pt[x-1].se<=v)
            {
                cout << "Yes\n";
            }
            else
            {
                cout << "No\n";
                //if(xx==68) assert(0);
            }
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(NULL) ; cin.tie(nullptr) ; cout.tie(nullptr);
    int t = 1;// cin >> t;
    //cout << -1;
    while(t--)
    {
        solve();
        cout << "\n";
    }
}

Compilation message

trampoline.cpp: In function 'void solve()':
trampoline.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i = 1; i< nen.size(); i++)
      |                    ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16784 KB 200 token(s): yes count is 21, no count is 179
2 Correct 16 ms 17104 KB 200 token(s): yes count is 70, no count is 130
3 Correct 14 ms 16340 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 234 ms 65452 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 226 ms 65552 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 214 ms 64304 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 248 ms 65628 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 475 ms 64152 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 482 ms 64928 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 485 ms 65356 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 665 ms 66080 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 648 ms 65812 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1031 ms 73764 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15828 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 15 ms 15828 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 21 ms 16596 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 16 ms 15956 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 17 ms 16084 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 15 ms 15828 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1117 ms 76536 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 922 ms 68584 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 497 ms 65444 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1345 ms 88684 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 1069 ms 77760 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 493 ms 65504 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 477 ms 65444 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 477 ms 65200 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1004 ms 73760 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1067 ms 74612 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1247 ms 82316 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 533 ms 64664 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 477 ms 64404 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 565 ms 65760 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 781 ms 67724 KB 200000 token(s): yes count is 129674, no count is 70326