Submission #172770

#TimeUsernameProblemLanguageResultExecution timeMemory
172770arnold518Matryoshka (JOI16_matryoshka)C++14
100 / 100
473 ms13264 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4e5; struct Point { int x, y, p; }; int N, Q, ans[MAXN+10]; Point A[MAXN+10]; vector<int> xcomp, ycomp; int tree[MAXN+10]; void update(int i, int val) { for(; i<=xcomp.size(); i+=(i&-i)) tree[i]=max(tree[i], val); } int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret=max(ret, tree[i]); return ret; } int main() { int i, j; scanf("%d%d", &N, &Q); for(i=1; i<=N; i++) { scanf("%d%d", &A[i].x, &A[i].y); A[i].x*=-1; A[i].p=-1; xcomp.push_back(A[i].x); ycomp.push_back(A[i].y); } for(i=N+1; i<=N+Q; i++) { scanf("%d%d", &A[i].x, &A[i].y); A[i].x*=-1; A[i].p=i-N; xcomp.push_back(A[i].x); ycomp.push_back(A[i].y); } sort(xcomp.begin(), xcomp.end()); sort(ycomp.begin(), ycomp.end()); xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end()); ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end()); for(i=1; i<=N+Q; i++) A[i].x=lower_bound(xcomp.begin(), xcomp.end(), A[i].x)-xcomp.begin()+1; for(i=1; i<=N+Q; i++) A[i].y=lower_bound(ycomp.begin(), ycomp.end(), A[i].y)-ycomp.begin()+1; sort(A+1, A+N+Q+1, [&](const Point &p, const Point &q) { if(pii(p.y, p.x)!=pii(q.y, q.x)) return pii(p.y, p.x)<pii(q.y, q.x); else return p.p<q.p; }); for(i=1; i<=N+Q; i++) { if(A[i].p==-1) update(A[i].x, query(A[i].x)+1); else ans[A[i].p]=query(A[i].x); } for(i=1; i<=Q; i++) printf("%d\n", ans[i]); }

Compilation message (stderr)

matryoshka.cpp: In function 'void update(int, int)':
matryoshka.cpp:20:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 void update(int i, int val) { for(; i<=xcomp.size(); i+=(i&-i)) tree[i]=max(tree[i], val); }
                                     ~^~~~~~~~~~~~~~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:25:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
matryoshka.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &Q);
     ~~~~~^~~~~~~~~~~~~~~~
matryoshka.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i].x, &A[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i].x, &A[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...