답안 #476517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476517 2021-09-27T13:09:13 Z leaked Trampoline (info1cup20_trampoline) C++14
100 / 100
760 ms 45760 KB
#include <bits/stdc++.h>

#define m_p make_pair
#define f first
#define s second
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<x)
#define sz(x) (int)x.size()
#define fast_ioi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long double ld;
typedef pair<long long,long long> pll;
template <class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template <class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
auto rng=bind(uniform_int_distribution<int>(1,20),mt19937(time(0)));
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int N=2e5+100;
const int lg=log2(N)+1;
int go[N][lg];
//void mg(int a,int b){
//    if(a==-1) return -1;
//
//}
signed main(){
    fast_ioi;
    int n,m,k;
    cin>>n>>m>>k;
    vec<pii>ar(k);
    for(auto &z : ar)
        cin>>z.f>>z.s;
    map<int,int> mpx;
    for(auto &z : ar) mpx[z.f]=1;
    vec<int>obrx;
    for(auto &z : mpx){z.s=sz(obrx);obrx.pb(z.f);}
//    debug()<<imie(mpx)imie(ar);
    for(auto &z : ar) z.f=mpx[z.f];
//    return 0;
    vec<set<pii>>st(sz(obrx));
//    vec<vec<int>>up(n,vec<int>())
    for(int i=0;i<k;i++){
//        cerr<<ar[i].f<<' '<<sz(st)<<endl;
//        system("pause");
        st[ar[i].f].insert({ar[i].s,i});
    }
    const int inf=1e9;
    for(int i=0;i<k;i++){
        if(ar[i].f==sz(obrx)-1 || obrx[ar[i].f+1]!=obrx[ar[i].f]+1){
            go[i][0]=-1;
            continue;
        }
        auto it=st[ar[i].f+1].lower_bound(m_p(ar[i].s,-inf));
        if(it==st[ar[i].f+1].end()) go[i][0]=-1;
        else go[i][0]=it->s;
    }
    for(int j=1;j<lg;j++){
        for(int i=0;i<k;i++){
            go[i][j]=(go[i][j-1]==-1?-1:go[go[i][j-1]][j-1]);
//            debug()<<imie(i)imie(j)imie(go[i][j])imie(go[i][j-1]);
        }
    }
    auto get=[&](int i,int dx){
        if(dx>k) return -1;
//        debug()<<imie(i)imie(dx);
        for(int j=0;j<lg;j++){
            if(pw(j)&dx){
                if(i==-1) i=-1;
                else i=go[i][j];
            }
        }
        return i;
    };
    int q;
    cin>>q;
    while(q--){
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        if(x1==x2 && y1<=y2){
            cout<<"Yes\n";
            continue;
        }
        if(y1>y2 || x1>x2){
            cout<<"No\n";
            continue;
        }
        if(!mpx.count(x1)){
            cout<<"No\n";
            continue;
        }
        x1=mpx[x1];
        auto it=st[x1].lower_bound(m_p(y1,-inf));
        if(it==st[x1].end()){
            cout<<"No\n";
            continue;
        }
        int j=it->s;
        j=get(j,x2-obrx[x1]-1);
        if(j==-1 || ar[j].s>y2){
            cout<<"No\n";
        }
        else{
            cout<<"Yes\n";
        }
    }
    return 0;
}
/*
6 1
5447 7526 7703 8705 18716 19718 19895
1582 7087 7911 14379 14703 14703 19265 19265 19589 26057 32386
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1356 KB 200 token(s): yes count is 21, no count is 179
2 Correct 6 ms 1588 KB 200 token(s): yes count is 70, no count is 130
3 Correct 4 ms 1228 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 25628 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 232 ms 25580 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 238 ms 25412 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 233 ms 25620 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 25968 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 446 ms 26292 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 461 ms 26036 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 469 ms 26272 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 442 ms 26216 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 494 ms 32572 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 972 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 7 ms 972 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 8 ms 1488 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 6 ms 972 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 7 ms 1144 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 6 ms 972 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 670 ms 33876 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 557 ms 28032 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 474 ms 26020 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 760 ms 45760 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 618 ms 33228 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 509 ms 26104 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 564 ms 26108 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 451 ms 25992 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 626 ms 32624 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 708 ms 32644 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 703 ms 39136 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 408 ms 37764 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 452 ms 37936 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 540 ms 37980 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 480 ms 37728 KB 200000 token(s): yes count is 129674, no count is 70326