Submission #849290

#TimeUsernameProblemLanguageResultExecution timeMemory
849290mickey080929Matryoshka (JOI16_matryoshka)C++17
100 / 100
218 ms17084 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef pair<int,int> pii; struct Query{ int A, B, id; }; int N, Q; pii a[200010]; Query q[200010]; int ans[200010]; struct BIT{ int tree[400010]; BIT() { memset(tree, 0, sizeof(tree)); } void update(int i, int val, int n) { while (i <= n) { tree[i] = max(tree[i], val); i += i & -i; } } int query(int i) { int res = 0; while (i > 0) { res = max(res, tree[i]); i -= i & -i; } return res; } } seg; int main() { scanf("%d %d", &N, &Q); vector<int> t; for (int i=1; i<=N; i++) { scanf("%d %d", &a[i].first, &a[i].second); t.push_back(a[i].second); } sort(a+1, a+N+1, [&] (pii &u, pii &v) { return u.first==v.first ? u.second < v.second : u.first > v.first; }); for (int i=1; i<=Q; i++) { scanf("%d %d", &q[i].A, &q[i].B); q[i].id = i; t.push_back(q[i].B); } sort(q+1, q+N+1, [&] (Query &u, Query &v) { return u.A > v.A; }); sort(t.begin(), t.end()); t.erase(unique(t.begin(), t.end()), t.end()); for (int i=1; i<=N; i++) { a[i].second = lower_bound(t.begin(), t.end(), a[i].second) - t.begin() + 1; } for (int i=1; i<=Q; i++) { q[i].B = lower_bound(t.begin(), t.end(), q[i].B) - t.begin() + 1; } int M = (int) t.size(); int j = 1; for (int i=1; i<=N; i++) { if (i == 1 || a[i].first < a[i-1].first) { while (j <= Q && q[j].A > a[i].first) { ans[q[j].id] = seg.query(q[j].B); j ++; } } int cur = seg.query(a[i].second); seg.update(a[i].second, cur+1, M); } while (j <= Q) { ans[q[j].id] = seg.query(q[j].B); j ++; } for (int i=1; i<=Q; i++) { printf("%d\n", ans[i]); } return 0; }

Compilation message (stderr)

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d %d", &N, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%d %d", &a[i].first, &a[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d %d", &q[i].A, &q[i].B);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...