Submission #919607

#TimeUsernameProblemLanguageResultExecution timeMemory
919607andrei_iorgulescuTrampoline (info1cup20_trampoline)C++14
43 / 100
1018 ms44356 KiB
#include <bits/stdc++.h> using namespace std; int r,c,n,q; int x[200005],y[200005]; map<int,vector<pair<int,int>>>v; int jump[20][200005]; set<int>st; int lg[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> r >> c >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; v[x[i]].push_back({y[i],i}); st.insert(x[i]); } for (auto it : st) sort(v[it].begin(),v[it].end()); for (int i = 1; i <= n; i++) { int xx = x[i] + 1,yy = y[i]; int st = -1,pas = 1 << 17; while (pas != 0) { if (st + pas < v[xx].size() and v[xx][st + pas].first < yy) st += pas; pas /= 2; } st++; if (st == v[xx].size()) jump[0][i] = -1; else jump[0][i] = v[xx][st].second; } for (int i = 2; i <= n; i++) lg[i] = 1 + lg[i / 2]; for (int b = 1; b <= lg[n]; b++) { for (int i = 1; i <= n; i++) { if (jump[b - 1][i] == -1) jump[b][i] = -1; else jump[b][i] = jump[b - 1][jump[b - 1][i]]; } } cin >> q; for (int i = 1; i <= q; i++) { int xs,ys,xf,yf; cin >> xs >> ys >> xf >> yf; if (xs > xf or ys > yf) cout << "No\n"; else if (xs == xf) cout << "Yes\n"; else { int xx = xs,yy = ys; int st = -1,pas = 1 << 17; //cout << yy << ' ' << v[xx][0].first << '\n'; while (pas != 0) { if (st + pas < v[xx].size() and v[xx][st + pas].first < yy) st += pas; pas /= 2; } st++; //cout << st << ' '; if (st == v[xx].size()) cout << "No\n"; else { int tr = v[xx][st].second; //cout << tr << ' '; for (int b = lg[n]; b >= 0; b--) { //cout << jump[b][tr] << ' '; if (jump[b][tr] != -1 and y[jump[b][tr]] <= yf) tr = jump[b][tr]; } if (x[tr] + 1 >= xf) cout << "Yes\n"; else cout << "No\n"; } } } return 0; } /** next[i] = care e urmatoarea verde in care as merge din trambulina i fac binary lifting pe treaba asta vad in ce trambulina verde urc si daca pe jumpurile aleia ajung la linia xf inainte de yf **/

Compilation message (stderr)

trampoline.cpp: In function 'int main()':
trampoline.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
      |                 ~~~~~~~~~^~~~~~~~~~~~~~
trampoline.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (st == v[xx].size())
      |             ~~~^~~~~~~~~~~~~~~
trampoline.cpp:70:30: 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 + pas < v[xx].size() and v[xx][st + pas].first < yy)
      |                     ~~~~~~~~~^~~~~~~~~~~~~~
trampoline.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             if (st == v[xx].size())
      |                 ~~~^~~~~~~~~~~~~~~
#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...