Submission #387596

#TimeUsernameProblemLanguageResultExecution timeMemory
3875968e7Trampoline (info1cup20_trampoline)C++14
100 / 100
601 ms41212 KiB
//Challenge: Accepted #include <iostream> #include <algorithm> #include <vector> #include <utility> #include <assert.h> #define ll long long #define maxn 200005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; //#include <bits/extc++.h> //using namespace __gnu_pbds; //template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //find by order, order of key vector<int> xv; pii orig[maxn]; pii pos[maxn]; vector<int> pnt[maxn], ind[maxn]; bool con[maxn]; int to[18][maxn]; int main() { io int r, c, n; cin >> r >> c >> n; for (int i = 0;i < n;i++) { cin >> orig[i].ff >> orig[i].ss; xv.push_back(orig[i].ff); } sort(xv.begin(), xv.end()); xv.resize(int(unique(xv.begin(), xv.end()) - xv.begin())); //for (int i:xv) cout << i << endl; for (int i = 0;i < n;i++) { int posid = lower_bound(xv.begin(), xv.end(), orig[i].ff) - xv.begin(); pnt[posid].push_back(orig[i].ss); } int tot = 1; for (int i = 0;i < xv.size();i++) { sort(pnt[i].begin(), pnt[i].end()); for (int j = 0;j < pnt[i].size();j++) { pos[tot] = make_pair(i, pnt[i][j]); ind[i].push_back(tot++); } if (i < xv.size() - 1) { con[i] = xv[i + 1] == xv[i] + 1 ? 1 : 0; } } pos[tot] = make_pair(maxn - 2, c + 1); for (int i = 1;i < tot;i++) { if (con[pos[i].ff]) { int id = lower_bound(pnt[pos[i].ff + 1].begin(), pnt[pos[i].ff + 1].end(), pos[i].ss) - pnt[pos[i].ff + 1].begin(); if (id >= ind[pos[i].ff + 1].size()) { to[0][i] = tot; } else { to[0][i] = ind[pos[i].ff + 1][id]; } } else { to[0][i] = tot; } } to[0][tot] = tot; for (int i = 1;i < 18;i++) { for (int j = 1;j <= tot;j++) to[i][j] = to[i - 1][to[i - 1][j]]; } int t; cin >> t; while (t--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 > x2) { cout << "No" << "\n"; continue; } if (x1 == x2) { cout << (y1 <= y2 ? "Yes" : "No") << "\n"; } else { int comp = lower_bound(xv.begin(), xv.end(), x1) - xv.begin(); int ans = 1; if (comp >= xv.size()) { ans = 0; } else if (xv[comp] != x1) { ans = 0; } else { x2--; int dif = x2 - x1; int id = lower_bound(pnt[comp].begin(), pnt[comp].end(), y1) - pnt[comp].begin(); if (id >= ind[comp].size() || dif >= maxn) { ans = 0; } else { int cur = ind[comp][id], cnt = 0; while (dif) { if (dif & 1) cur = to[cnt][cur]; cnt++, dif>>=1; } if (pos[cur].ss > y2) { ans = 0; } } } cout << (ans ? "Yes" : "No") << "\n"; } } } /* 4 5 2 1 2 3 4 3 2 1 4 5 1 2 1 4 3 3 4 4 */

Compilation message (stderr)

trampoline.cpp: In function 'int main()':
trampoline.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0;i < xv.size();i++) {
      |                 ~~^~~~~~~~~~~
trampoline.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int j = 0;j < pnt[i].size();j++) {
      |                  ~~^~~~~~~~~~~~~~~
trampoline.cpp:50:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   if (i < xv.size() - 1) {
      |       ~~^~~~~~~~~~~~~~~
trampoline.cpp:58:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    if (id >= ind[pos[i].ff + 1].size()) {
      |        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
trampoline.cpp:86:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    if (comp >= xv.size()) {
      |        ~~~~~^~~~~~~~~~~~
trampoline.cpp:94:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     if (id >= ind[comp].size() || dif >= maxn) {
      |         ~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...