Submission #523029

# Submission time Handle Problem Language Result Execution time Memory
523029 2022-02-06T19:02:33 Z Neacsu_Mihai Trampoline (info1cup20_trampoline) C++14
0 / 100
254 ms 18216 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#define NMAX 200005 //doua sute cincizeci de mii

using namespace std;

ifstream fin ("test.in");
ofstream fout ("test.out");

int R, C, N, T;
pair <int, int> s[NMAX + 1];
int t[25][200005];

int cautareBinara(int x,int y)
{
    int st=1,dr=N,mij=0,ras=0;
    while (st<=dr)
    {
        mij=(st+dr)/2;
        if (s[mij].first>x) {dr=mij-1;}
        else if (s[mij].first<x) {st=mij+1;}
        else if (s[mij].second<y) {st=mij+1;}
        else {dr=mij-1; ras=mij;}
    }
    return ras;
}
/*
int cautareBinara(int x, int y){

        //Imi returneaza, din lista de trambuline verzi, numarul celei de pe linia x, cu lowerboundul ei = y
        //daca nu exista niciunul pe linia x, returneaza 0


    int lo = 0;
    int hi = N + 1;
    int ans = 0;

    while(hi - lo > 1){
        int mid = lo + (hi - lo) / 2;

        if(s[mid].first > x){
            hi = mid;
        }
        else if(s[mid].first < x){
            lo = mid;
        }
        else if(s[mid].second < y){
            lo = mid;
        }
        else {
            ans = mid;
            hi = mid;
        }
    }

    return ans;
}*/
/*
int stramos(int node, int nr){
    if(nr == 0){
        return YMAX + 1;
    }

    for(int i = 19; i >= 0; i--){
        if( (1 << i) <= nr ){
            node = t[i][node];
            nr -= (1 << i);
        }
    }
    ///daca node ajunge sa fie 0, inseamna ca nu exista al nr-lea stramos al lui node
    ///dar la mine trebuie sa existe ca sa zic 'Yes', ca altfel inseamna ca nu am destule trambuline pe drum
    ///adica inseamna ca nu am trambuline de la (xs, xf) destule
    ///si atunci vreau sa returnez ceva care sa ma faca sa afisez 'No', adica returnez un 'y' f mare, pentru ca eu urmeaza sa il compar cu yf
    if(node == 0){
        return YMAX + 1;
    }

    return s[node].second; ///returneaza 'y'-ul celui de-al 'nr'-ulea stramos al lui 'node'
}
*/

int stramos(int nod,int lvl)
{
    for (int i=19;i>=0;--i)
    {
        if ((1<<i)<=lvl)
        {
            nod=t[i][nod];
            lvl-=(1<<i);
        }
    }
    if (nod==0) return 2000000000;
    return s[nod].second;
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);

    cin >> R >> C >> N; ///globale

    for(int i = 1; i <= N; i++){
        cin >> s[i].first >> s[i].second;
    }
    sort(s + 1, s + N + 1);

    for(int i = 1; i <= N; i++){
        int aux = cautareBinara(s[i].first + 1, s[i].second);
        t[0][i] = aux;
    }
    for(int i = 1; i <= 19; i++){
        for(int j = 1; j <= N; j++){
            t[i][j] = t[i - 1][ t[i - 1][j] ];
        }
    }


    cin >> T; ///global
    for(int Q = 1; Q <= T; Q++){

        int xs, ys, xf, yf;
        cin >> xs >> ys >> xf >> yf;

        if(xf == xs){ ///caz special ca altfel am niste valori cu -1 si nu are sens
            if(ys <= yf){
                cout << "Yes\n";
            }
            else {
                cout << "No\n";
            }
        }
        else {
            int st = cautareBinara(xs, ys); ///caut cel mai din stanga valid de pe linia 'xs'
            if(st == 0){
                cout << "No\n";
            }
            if( stramos(st, xf - 1 - xs) <= yf ){ ///verific al 'xf - 1 - xs'-lea stramos al acestuia si verific daca e mai mic ca 'yf'
                cout << "Yes\n";
            }
            else {
                cout << "No\n";
            }
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1100 KB expected NO, found YES [27th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 17500 KB 4000 token(s): yes count is 99, no count is 3901
2 Incorrect 65 ms 17436 KB expected YES, found NO [853rd token]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 18144 KB expected YES, found NO [5150th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 844 KB expected NO, found YES [17th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 254 ms 18216 KB expected NO, found YES [37th token]
2 Halted 0 ms 0 KB -