# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
331325 |
2020-11-28T02:51:17 Z |
Falcon |
None (JOI16_matryoshka) |
C++17 |
|
347 ms |
17112 KB |
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.hpp"
#endif
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N) for(int i = 0; i < (N); ++i)
#define rrep(i, N) for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N) for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e) for(int i = (s); i <= (e); ++i)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#ifdef DEBUG
#define debug(x...) { \
++dbg::depth; \
string dbg_vals = dbg::to_string(x); \
--dbg::depth; \
dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
}
#define light_debug(x) { \
dbg::light = true; \
dbg::dout << __func__ << ":" << __LINE__; \
dbg::dout << " " << #x << " = " << x << endl; \
dbg::light = false; \
}
#else
#define debug(x...) 42
#define light_debug(x) 42
#endif
using ll = long long;
template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
template<int n>
class segment_tree {
array<int, n << 1> a;
public:
void update(int i, int v) {
for(a[i += n] = v, i >>= 1; i > 0; i >>= 1)
a[i] = max(a[i << 1], a[i << 1 | 1]);
}
int query(int s, int e) const {
int r{};
for(s += n, e += n; s < e; s >>= 1, e >>= 1) {
if(s & 1) ckmax(r, a[s++]);
if(e & 1) ckmax(r, a[--e]);
}
return r;
}
};
constexpr int MAXV{2'00'000};
segment_tree<MAXV> seg;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef DEBUG
freopen("debug", "w", stderr);
#endif
int N, Q; cin >> N >> Q;
vector<pair<int, int>> v(N);
rep(i, N) cin >> v[i].first >> v[i].second, v[i].second = MAXV - v[i].second;
sort(rall(v));
struct compress {
vector<int> values;
void insert(int x) { values.push_back(x); }
void apply() { sort(all(values)); values.erase(unique(all(values)), values.end()); }
int get_rank(int x) const { return int(lower_bound(all(values), x) - values.begin()); }
};
compress X, Y;
for(const auto& [x, y] : v) X.insert(x), Y.insert(y);
X.apply(), Y.apply();
for(auto& [x, y] : v) x = X.get_rank(x), y = Y.get_rank(y);
struct query { int A, B, i; };
vector<query> queries; queries.reserve(Q);
rep(i, Q) {
int A, B; cin >> A >> B; B = MAXV - B;
A = X.get_rank(A), B = Y.get_rank(B);
queries.push_back({A, B, i});
}
sort(rall(queries),[](const query& a, const query& b) { return a.A < b.A; });
auto p = v.begin();
vector<int> ans(Q);
for(const query& q : queries) {
debug(q.i, q.A, q.B);
for(; p != v.end() && p->first >= q.A; ++p) {
debug(*p, 1 + seg.query(p->second, MAXV));
seg.update(p->second, 1 + seg.query(p->second, MAXV));
}
ans[q.i] = seg.query(q.B, MAXV);
}
for(int x : ans) cout << x << '\n';
#ifdef DEBUG
dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC << "ms" << endl;
#endif
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:35:29: warning: statement has no effect [-Wunused-value]
35 | #define debug(x...) 42
| ^~
matryoshka.cpp:121:9: note: in expansion of macro 'debug'
121 | debug(q.i, q.A, q.B);
| ^~~~~
matryoshka.cpp:35:29: warning: statement has no effect [-Wunused-value]
35 | #define debug(x...) 42
| ^~
matryoshka.cpp:123:13: note: in expansion of macro 'debug'
123 | debug(*p, 1 + seg.query(p->second, MAXV));
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
376 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
376 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
4 ms |
620 KB |
Output is correct |
24 |
Correct |
3 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
3 ms |
492 KB |
Output is correct |
34 |
Correct |
3 ms |
492 KB |
Output is correct |
35 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
376 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
4 ms |
620 KB |
Output is correct |
24 |
Correct |
3 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
3 ms |
492 KB |
Output is correct |
34 |
Correct |
3 ms |
492 KB |
Output is correct |
35 |
Correct |
3 ms |
492 KB |
Output is correct |
36 |
Correct |
330 ms |
13784 KB |
Output is correct |
37 |
Correct |
241 ms |
12120 KB |
Output is correct |
38 |
Correct |
108 ms |
5984 KB |
Output is correct |
39 |
Correct |
198 ms |
10584 KB |
Output is correct |
40 |
Correct |
196 ms |
11148 KB |
Output is correct |
41 |
Correct |
274 ms |
12120 KB |
Output is correct |
42 |
Correct |
138 ms |
9688 KB |
Output is correct |
43 |
Correct |
116 ms |
9816 KB |
Output is correct |
44 |
Correct |
340 ms |
16856 KB |
Output is correct |
45 |
Correct |
347 ms |
16856 KB |
Output is correct |
46 |
Correct |
347 ms |
16856 KB |
Output is correct |
47 |
Correct |
325 ms |
16684 KB |
Output is correct |
48 |
Correct |
321 ms |
17052 KB |
Output is correct |
49 |
Correct |
333 ms |
16728 KB |
Output is correct |
50 |
Correct |
327 ms |
17112 KB |
Output is correct |