Submission #369197

# Submission time Handle Problem Language Result Execution time Memory
369197 2021-02-20T21:11:42 Z doowey Trampoline (info1cup20_trampoline) C++14
100 / 100
634 ms 56672 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)4e5 + 10;
const int LOG = 19;
int ii[N], jj[N];
int nx[LOG][N];

vector<pii> imp;

int fin(pii xx){
    return lower_bound(imp.begin(), imp.end(), xx) - imp.begin();
}

int main(){
    fastIO;
    int r,c,t;
    cin >> r >> c >> t;
    set<pii> aq;

    for(int id = 0; id < t; id ++ ){
        cin >> ii[id] >> jj[id];
        aq.insert(mp(ii[id], jj[id]));
        imp.push_back(mp(ii[id], jj[id]));
        imp.push_back(mp(ii[id] + 1, jj[id]));
    }
    sort(imp.begin(), imp.end());
    imp.resize(unique(imp.begin(), imp.end()) - imp.begin());
    int m = imp.size();
    int ni = -1;
    for(int i = m - 1; i >= 0; i -- ){
        if(i == m - 1 || imp[i].fi != imp[i + 1].fi)
            ni = -1;
        if(aq.count(imp[i])){
            ni = fin(mp(imp[i].fi + 1, imp[i].se));
        }
        nx[0][i] = ni;
    }
    for(int i = 1; i < LOG; i++ ){
        for(int j = 0 ;j < m ; j ++ ){
            if(nx[i-1][j] != -1){
                nx[i][j]=nx[i-1][nx[i-1][j]];
            }
        }
    }
    int q;
    cin >> q;
    int i1, j1, i2, j2;
    int st;
    for(int id = 0; id < q; id ++ ){
        cin >> i1 >> j1 >> i2 >> j2;
        if(i1 > i2 || j1 > j2){
            cout << "No\n";
        }
        else{
            if(i1 == i2){
                cout << "Yes\n";
            }
            else{
                st = lower_bound(imp.begin(), imp.end(), mp(i1, j1)) - imp.begin();
                if(st == imp.size() || imp[st].fi != i1){
                    cout << "No\n";
                }
                else{
                    for(int q = 0; q < LOG; q ++ ){
                        if(((i2-i1)&(1<<q))){
                            if(st != -1) st = nx[q][st];
                        }
                    }
                    if(st != -1 && imp[st].fi == i2 && imp[st].se <= j2){
                        cout << "Yes\n";
                    }
                    else{
                        cout << "No\n";
                    }
                }
            }
        }
    }
    return 0;
}

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |                 if(st == imp.size() || imp[st].fi != i1){
      |                    ~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2280 KB 200 token(s): yes count is 21, no count is 179
2 Correct 10 ms 2536 KB 200 token(s): yes count is 70, no count is 130
3 Correct 7 ms 2028 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 277 ms 43860 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 282 ms 45708 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 271 ms 33492 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 290 ms 45524 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 428 ms 43860 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 453 ms 44756 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 432 ms 44756 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 448 ms 45264 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 438 ms 44884 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 436 ms 44884 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1644 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 9 ms 1900 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 8 ms 1900 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 9 ms 1900 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 9 ms 1900 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 8 ms 1900 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 575 ms 45032 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 570 ms 45056 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 459 ms 44896 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 634 ms 56616 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 513 ms 56176 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 470 ms 56444 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 480 ms 56532 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 460 ms 56660 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 603 ms 56552 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 616 ms 56672 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 605 ms 56532 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 427 ms 56024 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 461 ms 56532 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 512 ms 56648 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 441 ms 55124 KB 200000 token(s): yes count is 129674, no count is 70326