Submission #675377

# Submission time Handle Problem Language Result Execution time Memory
675377 2022-12-27T07:17:05 Z Hiennoob123 Trampoline (info1cup20_trampoline) C++14
100 / 100
1377 ms 88688 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 16832 KB 200 token(s): yes count is 21, no count is 179
2 Correct 17 ms 17004 KB 200 token(s): yes count is 70, no count is 130
3 Correct 14 ms 16312 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 229 ms 65528 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 237 ms 65500 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 209 ms 64300 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 226 ms 65576 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 479 ms 64332 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 486 ms 64976 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 510 ms 65404 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 746 ms 65964 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 731 ms 65836 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1053 ms 73676 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 18 ms 15828 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 18 ms 16596 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 16 ms 15960 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 17 ms 16048 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 14 ms 15828 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1129 ms 76316 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 898 ms 68532 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 498 ms 65432 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1377 ms 88688 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 1083 ms 77876 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 509 ms 65392 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 496 ms 65600 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 486 ms 65024 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1044 ms 73732 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1104 ms 74676 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1322 ms 82552 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 533 ms 64624 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 482 ms 64272 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 618 ms 65832 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 805 ms 67436 KB 200000 token(s): yes count is 129674, no count is 70326