답안 #311733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311733 2020-10-11T09:22:36 Z grt Trampoline (info1cup20_trampoline) C++17
0 / 100
922 ms 40408 KB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using ll = long long;
using pi = pair<int,int>;

#define ST first
#define ND second
#define PB push_back

const int nax = 200 * 1000 + 10;
int r, c, t, n, nr;
map<int, int>sc;
vi T[nax];
pi p[nax];
int nxt[nax][19];

bool cmp(int a, int b) {
    return p[a].ND < p[b].ND;
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> r >> c >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> p[i].ST >> p[i].ND;
        sc[p[i].ST];
    }
    for(auto &it : sc) it.ND = ++nr;
    for(int i = 1; i <= n; ++i) {
        T[sc[p[i].ST]].PB(i);
    }
    for(int i = 1; i <= nr; ++i) {
        sort(T[i].begin(), T[i].end(), cmp);
    }
    for(int i = 1; i <= n; ++i) {
        if(sc.find(p[i].ST + 1) == sc.end()) {
            nxt[i][0] = i;
        } else {
            int y = sc[p[i].ST + 1];
            int low = 0, high = (int)T[y].size() - 1, mid;
            while(low <= high) {
                mid = (low + high) / 2;
                if(p[T[y][mid]].ND >= p[i].ND) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            high++;
            if(high == (int)T[y].size()) {
                nxt[i][0] = i;
            } else {
                nxt[i][0] = T[y][high];
            }
        }
    }
    for(int step = 1; step < 19; ++step) {
        for(int i = 1; i <= n; ++i) {
            nxt[i][step] = nxt[nxt[i][step - 1]][step - 1];
        }
    }
    cin >> t;
    while(t--) {
        int x, y, a, b;
        cin >> x >> y >> a >> b;
        if(x > a || y > b) {
            cout << "No\n";
            continue;
        }
        if(x == a) {
            cout << "Yes\n";
            continue;
        }
        if(sc.find(x) == sc.end()) {
            cout << "No\n";
            continue;
        }
        int start = sc[x];
        int low = 0, high = (int)T[start].size() - 1, mid;
        while(low <= high) {
            mid = (low + high) / 2;
            if(p[T[start][mid]].ND >= y) {
                high = mid - 1;
            } else {
                low = high + 1;
            }
        }
        high++;
        if(high == (int)T[start].size()) {
            cout << "No\n";
            continue;
        }
        int w = T[start][high];
        for(int step = 18; step >= 0; --step) {
            if(p[nxt[w][step]].ST <= a) {
                w = nxt[w][step];
            }
        }
        if((p[w].ST != a && p[w].ST != (a - 1)) || p[w].ND > b) {
            cout << "No\n";
            continue;
        }
        cout << "Yes\n";
    }


}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 5888 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 212 ms 24824 KB expected YES, found NO [32nd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 282 ms 34932 KB expected YES, found NO [4th token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 5760 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 922 ms 40408 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -