답안 #987044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987044 2024-05-21T18:34:51 Z Zbyszek99 Trampoline (info1cup20_trampoline) C++17
100 / 100
1991 ms 206872 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

ll pair_to_int(pair<int,int> a)
{
    ll p = a.ff;
    ll p2 = a.ss;
    return p + p2*1000000005LL;
}

pair<int,int> int_to_pair(ll x)
{
    ll p2 = x / 1000000005LL;
    ll p = x - p2*1000000005LL;
    swap(p2,p);
    return {p2,p};
}

unordered_map<int, int> mapa;
vector<int> pon[200001];
unordered_map<ll,ll> next_[19];

int find_next(int y, int x)
{
  //  cout << "finding " << y << " " << x << " \n";
    int pocz = 0;
    int kon = size(pon[y])-1;
    int wyn = -1;
    while(pocz <= kon)
    {
        int srod = (pocz+kon)/2;
        if(pon[y][srod] >= x)
        {
            kon = srod-1;
            wyn = pon[y][srod];
        }
        else
        {
            pocz = srod+1;
        }
    }
    return wyn;
}

void solve()
{
    int R,C,n;
    cin >> R >> C >> n;
    vector<int> byly;
    vector<pair<int,int>> points;
  // cout << pair_to_int({2137,56}) << " " << int_to_pair(pair_to_int({2137,56})).ff << " " << int_to_pair(pair_to_int({2137,56})).ss << " xd\n";
    rep(i,n)
    {
        int x,y;
        cin >>y >> x;
        if(mapa[y] == 0) mapa[y] = i+1;
        pon[mapa[y]].pb(x);
        points.pb({y,x});
    }
    forall(it, mapa) sort(all(pon[it.ss]));
    int pop = -1;
    forall(it, mapa)
    {
        //cout << it.ff << " " << it.ss << " b\n"; 
        if(it.ff != pop) byly.pb(it.ff);
        pop = it.ff;
    }
    sort(all(byly));
    rep(i,size(byly))
    {
        //cout << byly[i] << i << " " <<size(byly)-1  << " byly\n";
        if(i == size(byly)-1 || byly[i] != byly[i+1]-1)
        {
            forall(it2,pon[mapa[byly[i]]])
            {
                next_[0][pair_to_int({byly[i],it2})] = pair_to_int({byly[i],it2});
            }
        }
        else
        {
            forall(it2,pon[mapa[byly[i]]])
            {
                int iter = find_next(mapa[byly[i+1]],it2);
                if(iter != -1)
                {
                    next_[0][pair_to_int({byly[i],it2})] = pair_to_int({byly[i+1],iter});
                }
                else
                {
                    next_[0][pair_to_int({byly[i],it2})] = pair_to_int({byly[i],it2});
                }
            }
        }
    }
    rep2(k,1,18)
    {
        forall(it,points)
        {
            next_[k][pair_to_int(it)] = next_[k-1][next_[k-1][pair_to_int(it)]];
        }
    }
    int q;
    cin >> q;
    rep(i,q)
    {
        int y1,x1,y2,x2;
        cin >> y1 >> x1 >> y2 >> x2;
        int odl = y2-y1-1;
        if(y2 < y1 || x2 < x1)
        {
            cout << "No\n"; continue;
        }
        if(y1 == y2)
        {
            cout << "Yes\n"; continue;
        }
        int aktpoint_iter = find_next(mapa[y1],x1);
        if(aktpoint_iter  == -1)
        {
            cout << "No\n"; continue;
        } 
        pair<int,int> aktpoint = {y1,aktpoint_iter};
        rep(k,18)
        {
           // cout << aktpoint.ff << " " << aktpoint.ss << " " << next_[k][pair_to_int(aktpoint)] << " aktpoint\n";
            if(odl & (1 << k))
            {
                aktpoint = int_to_pair(next_[k][pair_to_int(aktpoint)]);
            }
        }
        if(aktpoint.ff == y2-1 && aktpoint.ss <= x2)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // random();
    int t = 1;
    //cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 11860 KB 200 token(s): yes count is 21, no count is 179
2 Correct 29 ms 12564 KB 200 token(s): yes count is 70, no count is 130
3 Correct 22 ms 10844 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 1124 ms 180084 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 1219 ms 180032 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 888 ms 179728 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 1126 ms 179844 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 1197 ms 180024 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 1244 ms 179912 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 1248 ms 180172 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 1268 ms 180344 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 1317 ms 180364 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1359 ms 184552 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 8792 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 18 ms 8796 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 17 ms 9244 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 16 ms 8968 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 19 ms 9052 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 16 ms 8796 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 1973 ms 185532 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 1684 ms 193400 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 1334 ms 192300 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1991 ms 206872 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 1540 ms 196688 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 1391 ms 192128 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 1331 ms 192184 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 1267 ms 191728 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1849 ms 196192 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1912 ms 196232 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1970 ms 201272 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 1167 ms 191868 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 1164 ms 191696 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 1565 ms 192292 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 1183 ms 191636 KB 200000 token(s): yes count is 129674, no count is 70326