Submission #919607

# Submission time Handle Problem Language Result Execution time Memory
919607 2024-02-01T08:45:56 Z andrei_iorgulescu Trampoline (info1cup20_trampoline) C++14
43 / 100
1018 ms 44356 KB
#include <bits/stdc++.h>

using namespace std;

int r,c,n,q;
int x[200005],y[200005];
map<int,vector<pair<int,int>>>v;
int jump[20][200005];
set<int>st;
int lg[200005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> r >> c >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x[i] >> y[i];
        v[x[i]].push_back({y[i],i});
        st.insert(x[i]);
    }
    for (auto it : st)
        sort(v[it].begin(),v[it].end());
    for (int i = 1; i <= n; i++)
    {
        int xx = x[i] + 1,yy = y[i];
        int st = -1,pas = 1 << 17;
        while (pas != 0)
        {
            if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
                st += pas;
            pas /= 2;
        }
        st++;
        if (st == v[xx].size())
            jump[0][i] = -1;
        else
            jump[0][i] = v[xx][st].second;
    }
    for (int i = 2; i <= n; i++)
        lg[i] = 1 + lg[i / 2];
    for (int b = 1; b <= lg[n]; b++)
    {
        for (int i = 1; i <= n; i++)
        {
            if (jump[b - 1][i] == -1)
                jump[b][i] = -1;
            else
                jump[b][i] = jump[b - 1][jump[b - 1][i]];
        }
    }
    cin >> q;
    for (int i = 1; i <= q; i++)
    {
        int xs,ys,xf,yf;
        cin >> xs >> ys >> xf >> yf;
        if (xs > xf or ys > yf)
            cout << "No\n";
        else if (xs == xf)
            cout << "Yes\n";
        else
        {
            int xx = xs,yy = ys;
            int st = -1,pas = 1 << 17;
            //cout << yy << ' ' << v[xx][0].first << '\n';
            while (pas != 0)
            {
                if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
                    st += pas;
                pas /= 2;
            }
            st++;
            //cout << st << ' ';
            if (st == v[xx].size())
                cout << "No\n";
            else
            {
                int tr = v[xx][st].second;
                //cout << tr << ' ';
                for (int b = lg[n]; b >= 0; b--)
                {
                    //cout << jump[b][tr] << ' ';
                    if (jump[b][tr] != -1 and y[jump[b][tr]] <= yf)
                        tr = jump[b][tr];
                }
                if (x[tr] + 1 >= xf)
                    cout << "Yes\n";
                else
                    cout << "No\n";
            }
        }
    }
    return 0;
}

/**
next[i] = care e urmatoarea verde in care as merge din trambulina i
fac binary lifting pe treaba asta
vad in ce trambulina verde urc si daca pe jumpurile aleia ajung la linia xf inainte de yf
**/

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
      |                 ~~~~~~~~~^~~~~~~~~~~~~~
trampoline.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (st == v[xx].size())
      |             ~~~^~~~~~~~~~~~~~~
trampoline.cpp:70:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |                 if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
      |                     ~~~~~~~~~^~~~~~~~~~~~~~
trampoline.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             if (st == v[xx].size())
      |                 ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14960 KB 200 token(s): yes count is 21, no count is 179
2 Correct 8 ms 14940 KB 200 token(s): yes count is 70, no count is 130
3 Correct 6 ms 12892 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 266 ms 23376 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 270 ms 23320 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 185 ms 22168 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 269 ms 23272 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 32964 KB expected NO, found YES [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 13144 KB expected NO, found YES [125th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1018 ms 44356 KB expected NO, found YES [90481st token]
2 Halted 0 ms 0 KB -