답안 #314446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314446 2020-10-20T00:05:17 Z limabeans Trampoline (info1cup20_trampoline) C++17
11 / 100
694 ms 51060 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 2e5 + 5;
const int LOG = 21;

int n,m,t;
map<pair<int,int>,int> mp;
int X[maxn], Y[maxn];

vector<int> xord;
vector<int> row[maxn];

int par[LOG+1][maxn];


bool solve(int x1, int y1, int x2, int y2) {
    if (x1>x2) return false;
    if (y1>y2) return false;
    if (x1==x2) return true;

    int xi = std::lower_bound(xord.begin(),xord.end(),x1)-xord.begin();
    if (xi==(int)xord.size() || xord[xi]!=x1) {
	return false;
    }

    int yi = std::lower_bound(row[xi].begin(),row[xi].end(),y1)-row[xi].begin();
    if (yi==(int)row[xi].size()) {
	return false;
    }

    int at = mp[{x1, row[xi][yi]}];

    int dx = x2-x1-1;
    for (int i=LOG-1; i>=0; i--) {
	if (dx>>i&1) {
	    at = par[i][at];
	}
    }

    if (at == 0) return false;
    return Y[at] <= y2;
}

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

    cin>>n>>m>>t;

    for (int i=1; i<=t; i++) {
	cin>>X[i]>>Y[i];
	mp[{X[i],Y[i]}] = i;
	xord.push_back(X[i]);
    }

    sort(xord.begin(),xord.end());
    
    for (int i=1; i<=t; i++) {
	int x = lower_bound(xord.begin(),xord.end(),X[i])-xord.begin();
	row[x].push_back(Y[i]);
    }

    for (int i=0; i<(int)xord.size() - 1; i++) {
	sort(row[i].begin(),row[i].end());
	if (xord[i]+1 == xord[i+1]) {
	    for (int y: row[i]) {
		int atId = mp[{xord[i],y}];
		int yto = std::lower_bound(row[i+1].begin(),row[i+1].end(),y)-row[i+1].begin();
		if (yto < (int)row[i+1].size()) {
		    int toId = mp[{xord[i]+1,row[i+1][yto]}];
		    par[0][atId] = toId;
		}

	    }
	}
    }


    for (int j=1; j<LOG; j++) {
	for (int i=1; i<=t; i++) {
	    par[j][i] = par[j-1][par[j-1][i]];
	}
    }

    int q;
    cin>>q;
    
    while (q--) {
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<(solve(x1,y1,x2,y2) ? "Yes\n" : "No\n");
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 6656 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 272 ms 37096 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 45160 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 509 ms 49384 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 537 ms 49132 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 598 ms 49256 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 627 ms 49280 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 630 ms 51060 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 6016 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 694 ms 47212 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -