# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
668307 |
2022-12-03T15:22:08 Z |
sysia |
None (JOI16_matryoshka) |
C++17 |
|
454 ms |
31268 KB |
//Sylwia Sapkowska
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
struct TreeMax{
vector<int>tab;
int size = 1;
TreeMax(int n){
while (size < n) size*=2;
tab.assign(2*size, 0);
}
int query(int l, int r){
int ans = 0;
for (l += size-1, r += size+1; r-l>1; l/=2, r/=2){
if (!(l&1)) ans = max(ans, tab[l+1]);
if (r&1) ans = max(ans, tab[r-1]);
}
return ans;
}
void update(int x, int v){
x += size;
tab[x] = max(tab[x], v);
while (x){
x/=2;
tab[x] = max(tab[2*x], tab[2*x+1]);
}
}
};
struct T{
int a, b, i;
T(){}
T(int _a, int _b, int _i){
a = _a, b = _b, i = _i;
}
};
void solve(){
int n, q; cin >> n >> q;
vector<pair<int, int>>tab;
vector<int>s = {0};
for (int i = 0; i<n; i++){
int r, h; cin >> r >> h;
tab.emplace_back(r, h);
s.emplace_back(h);
}
auto get = [&](int x){return lower_bound(s.begin(), s.end(), x)-s.begin();};
sort(tab.begin(), tab.end(), [&](auto x, auto y){
if (x.first == y.first) return x.second < y.second;
return x.first > y.first;
});
int ptr = 0;
TreeMax t(n+q+2);
vector<T>que;
for (int i = 0; i<q; i++){
int a,b; cin >> a >> b;
que.emplace_back(a, b, i);
s.emplace_back(b);
}
sort(que.begin(), que.end(), [&](auto x, auto y){
if (x.a == y.a) return x.b < y.b;
return x.a > y.a;
});
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
vector<int>ans(q+1);
for (auto [a, b, idx]:que){
while (ptr < n){
if (tab[ptr].first >= a){
t.update(get(tab[ptr].second), t.query(0, get(tab[ptr].second))+1);
ptr++;
} else break;
}
ans[idx] = t.query(0, get(b));
}
for (int i = 0; i<q; i++) cout << ans[i] << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
584 KB |
Output is correct |
24 |
Correct |
4 ms |
600 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
588 KB |
Output is correct |
28 |
Correct |
4 ms |
548 KB |
Output is correct |
29 |
Correct |
3 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
4 ms |
596 KB |
Output is correct |
32 |
Correct |
4 ms |
552 KB |
Output is correct |
33 |
Correct |
3 ms |
588 KB |
Output is correct |
34 |
Correct |
3 ms |
596 KB |
Output is correct |
35 |
Correct |
4 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
584 KB |
Output is correct |
24 |
Correct |
4 ms |
600 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
588 KB |
Output is correct |
28 |
Correct |
4 ms |
548 KB |
Output is correct |
29 |
Correct |
3 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
4 ms |
596 KB |
Output is correct |
32 |
Correct |
4 ms |
552 KB |
Output is correct |
33 |
Correct |
3 ms |
588 KB |
Output is correct |
34 |
Correct |
3 ms |
596 KB |
Output is correct |
35 |
Correct |
4 ms |
552 KB |
Output is correct |
36 |
Correct |
338 ms |
28420 KB |
Output is correct |
37 |
Correct |
201 ms |
27776 KB |
Output is correct |
38 |
Correct |
110 ms |
12136 KB |
Output is correct |
39 |
Correct |
195 ms |
26144 KB |
Output is correct |
40 |
Correct |
214 ms |
26708 KB |
Output is correct |
41 |
Correct |
259 ms |
27736 KB |
Output is correct |
42 |
Correct |
149 ms |
25400 KB |
Output is correct |
43 |
Correct |
103 ms |
25432 KB |
Output is correct |
44 |
Correct |
349 ms |
31036 KB |
Output is correct |
45 |
Correct |
371 ms |
31068 KB |
Output is correct |
46 |
Correct |
454 ms |
31060 KB |
Output is correct |
47 |
Correct |
365 ms |
30680 KB |
Output is correct |
48 |
Correct |
339 ms |
31268 KB |
Output is correct |
49 |
Correct |
392 ms |
30740 KB |
Output is correct |
50 |
Correct |
387 ms |
31256 KB |
Output is correct |