답안 #675274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675274 2022-12-27T03:43:51 Z uylulu Trampoline (info1cup20_trampoline) C++14
54 / 100
813 ms 480264 KB
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define int long long
#define endl "\n"

const int N = 3e5,K = 20;

int r,c,n,q,lg[N + 1];

map<int,vector<int>> green;

vector<vector<int>> idx;
vector<int> row;

vector<int> sparse[N + 1][K + 1];

int query(int r1,int c1,int r2) {
    r1--;
    r2--;

    int len = r2 - r1;
    if(r1 == r2) {
        auto it = lower_bound(idx[r1].begin(),idx[r1].end(),c1);
        return (*it);
    }
    auto it = lower_bound(idx[r1].begin(),idx[r1].end(),c1);

    if(it == idx[r1].end()) return LLONG_MAX;

    
    int pp = it - idx[r1].begin();

    int res = c1;
    for(int j = K;j >= 0;j--) {
        int tmp = (len >> j) % 2;

        if(tmp == 0) continue;

        int nxt = sparse[r1][j][pp];
        // cout<<j<<" "<<nxt<<" "<<r1<<" "<<pp<<endl;

        r1 += (1<<j);
        res = max(res,nxt);

        it = lower_bound(idx[r1].begin(),idx[r1].end(),nxt);
        
        if(it == idx[r1 + (1<<j)].end()) {
            return LLONG_MAX;
        }
        pp = it - idx[r1].begin();
    }
    return res;

}

map<int,int> uy;

signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);

    cin>>r>>c>>n;

    for(int i = 2;i <= N;i++) {
        lg[i] = lg[i/2] + 1;
    }    
    for(int i = 0;i < n;i++) {
        int x,y;
        cin>>x>>y;
        green[x].push_back(y);
    }
    for(auto u : green) {
        u.second.push_back(LLONG_MAX);
        sort(u.second.begin(),u.second.end());
        idx.push_back(u.second);
        row.push_back(u.first);
    }
    for(int i = 0;i < idx.size();i++) {
        for(int j = 0;j <= K;j++) {
            sparse[i][j].assign(idx[i].size(),0);
        }
    }
    for(int i = 0;i < idx.size();i++) {
        uy[row[i]] = i + 1;

        for(int j = 0;j < idx[i].size();j++) {
            if(i == (int)idx.size() - 1 || row[i] + 1 != row[i + 1]) {
                sparse[i][0][j] = LLONG_MAX;
            } else {
                auto it = lower_bound(idx[i + 1].begin(),idx[i + 1].end(),idx[i][j]);
                sparse[i][0][j] = (*it);
            }
        }
    }
    for(int j = 1;j <= K;j++) {
        for(int i = 0;i + (1<<j) <= (int)idx.size();i++) {
            for(int pp = 0;pp < idx[i].size();pp++) {

                int fi = sparse[i][j - 1][pp];

                auto it = lower_bound(idx[i + (1<<(j - 1))].begin(),idx[i + (1<<(j - 1))].end(),fi);

                if(row[i + (1<<(j - 1)) - 1] + 1 != row[i + (1<<(j - 1))]) {
                    // if(i == 0 && j == 1 && pp == 0) {
                    //     cout<<row[i + (1<<(j - 1)) - 1]<<" "<<row[i + (1<<(j - 1))]<<endl;
                    //     cout<<"HERE"<<endl;
                    // }
                    sparse[i][j][pp] = LLONG_MAX;
                } else {
                    int pos = it - idx[i + (1<<(j - 1))].begin();
                    // if(i == 0 && j == 1 && pp == 0) {
                    //     cout<<"HERE"<<endl;
                    // }
                    sparse[i][j][pp] = sparse[i + (1<<(j - 1))][j - 1][pos];
                }
            }

        }
    }

    int q;
    cin>>q;
    while(q--) {
        int r1,c1,r2,c2;
        cin>>r1>>c1>>r2>>c2;

        if(r1 > r2 || c1 > c2) {
            cout<<"NO"<<endl;
            continue;
        }
        if(r1 == r2) {
            cout<<"YES"<<endl;
            continue;
        }
        r1 = uy[r1];

        if(r1 == 0) {
            cout<<"NO"<<endl;
            continue;
        }

        int mn = LLONG_MAX;
        if(uy[r2] != 0) {
            mn = min(mn,query(r1,c1,uy[r2]));
        }
        if(uy[r2 - 1] != 0) {
            mn = min(mn,query(r1,c1,uy[r2 - 1]));
        }
        if(mn > c2) {
            cout<<"NO"<<endl;
        } else {
            cout<<"YES"<<endl;
        }
    }

    return 0;
}            

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:82:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0;i < idx.size();i++) {
      |                   ~~^~~~~~~~~~~~
trampoline.cpp:87:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i = 0;i < idx.size();i++) {
      |                   ~~^~~~~~~~~~~~
trampoline.cpp:90:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for(int j = 0;j < idx[i].size();j++) {
      |                       ~~^~~~~~~~~~~~~~~
trampoline.cpp:101:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             for(int pp = 0;pp < idx[i].size();pp++) {
      |                            ~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 152268 KB 200 token(s): yes count is 21, no count is 179
2 Correct 77 ms 152564 KB 200 token(s): yes count is 70, no count is 130
3 Correct 72 ms 151944 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 189300 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 192 ms 189108 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 182 ms 187592 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 174 ms 189180 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 187480 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 304 ms 187384 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 328 ms 187812 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 367 ms 189424 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 404 ms 189360 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 813 ms 229188 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 151600 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 80 ms 151540 KB 5000 token(s): yes count is 3837, no count is 1163
3 Runtime error 204 ms 314260 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 584 ms 480264 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -