답안 #675219

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

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

const int N = 2e5,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) {
    int len = r2 - r1,curr = idx[r1][c1];

    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];
        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;
        // cout<<x<<" "<<y<<endl;
        green[x].push_back(y);
    }
    auto it = green.begin();
    for(auto &u : green) {
        sort(u.second.begin(),u.second.end());
        it++;
        idx.push_back(u.second);
        row.push_back(u.first);

        // cout<<u.first<<endl;
        // for(auto x : u.second) {
        //     cout<<x<<" ";
        // }
        // cout<<endl<<endl;
    }
    for(int i = 0;i < idx.size();i++) {
        for(int j = 0;j <= K;j++) {
            sparse[i][j].assign(idx[i].size() + 1,0);
        }
    }
    for(int i = 0;i < idx.size();i++) {
        uy[row[i]] = i;
        for(int j = 0;j < idx[i].size();j++) {
            sparse[i][0][j] = idx[i][j];
        }
    }
    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++) {

                if(j == 1 && row[i] + 1 != row[i + 1]) {
                    sparse[i][j][pp] = LLONG_MAX;
                    continue;
                }
                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(it == idx[i + (1<<(j - 1))].end()) {
                    sparse[i][j][pp] = LLONG_MAX;
                } else {
                    int pos = it - idx[i + (1<<(j - 1))].begin();
                    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;
        }
        r1 = uy[r1];
        r2 = uy[r2];

        int fin = query(r1,c1,r2);
        if(fin > c2) {
            cout<<"NO"<<endl;
        } else {
            cout<<"YES"<<endl;
        }
    }

    return 0;
}            

Compilation message

trampoline.cpp: In function 'long long int query(long long int, long long int, long long int)':
trampoline.cpp:21:23: warning: unused variable 'curr' [-Wunused-variable]
   21 |     int len = r2 - r1,curr = idx[r1][c1];
      |                       ^~~~
trampoline.cpp: In function 'int main()':
trampoline.cpp:78: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]
   78 |     for(int i = 0;i < idx.size();i++) {
      |                   ~~^~~~~~~~~~~~
trampoline.cpp:83: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]
   83 |     for(int i = 0;i < idx.size();i++) {
      |                   ~~^~~~~~~~~~~~
trampoline.cpp:85: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]
   85 |         for(int j = 0;j < idx[i].size();j++) {
      |                       ~~^~~~~~~~~~~~~~~
trampoline.cpp:91: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]
   91 |             for(int pp = 0;pp < idx[i].size();pp++) {
      |                            ~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 100684 KB 200 token(s): yes count is 21, no count is 179
2 Correct 60 ms 100948 KB 200 token(s): yes count is 70, no count is 130
3 Correct 48 ms 100408 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 139036 KB 4000 token(s): yes count is 99, no count is 3901
2 Incorrect 147 ms 138964 KB expected NO, found YES [1386th token]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 245 ms 277184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 117 ms 202448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 520 ms 377756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -