QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879848 | #402. Matryoshka | woohyun_jng | 0 | 1ms | 16104kb | C++23 | 2.3kb | 2025-02-02 16:35:39 | 2025-02-02 16:35:39 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define MAX 400000
using namespace std;
typedef array<int, 2> pr;
typedef array<int, 3> tp;
int R[MAX], H[MAX], A[MAX], B[MAX], ans[MAX], tree[MAX * 4], num[MAX];
vector<int> arr[MAX], queries[MAX];
void update(int n, int s, int e, int x, int v) {
if (x < s || e < x)
return;
else if (s == e)
tree[n] = max(tree[n], v);
else {
int m = s + e >> 1;
update(n << 1, s, m, x, v), update(n << 1 | 1, m + 1, e, x, v);
tree[n] = max(tree[n << 1], tree[n << 1 | 1]);
}
}
int query(int n, int s, int e, int l, int r) {
if (r < s || e < l)
return 0;
else if (l <= s && e <= r)
return tree[n];
else {
int m = s + e >> 1;
return max(query(n << 1, s, m, l, r), query(n << 1 | 1, m + 1, e, l, r));
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int N, Q, SX, SY, X;
vector<int> Xcomp, Ycomp;
cin >> N >> Q;
for (int i = 1; i <= N; i++)
cin >> R[i] >> H[i], Xcomp.push_back(-R[i]), Ycomp.push_back(H[i]);
for (int i = 1; i <= Q; i++)
cin >> A[i] >> B[i], Xcomp.push_back(-A[i]), Ycomp.push_back(B[i]);
sort(Xcomp.begin(), Xcomp.end()), Xcomp.erase(unique(Xcomp.begin(), Xcomp.end()), Xcomp.end()), SX = Xcomp.size();
sort(Ycomp.begin(), Ycomp.end()), Ycomp.erase(unique(Ycomp.begin(), Ycomp.end()), Ycomp.end()), SY = Ycomp.size();
for (int i = 1; i <= N; i++) {
R[i] = lower_bound(Xcomp.begin(), Xcomp.end(), -R[i]) - Xcomp.begin() + 1;
H[i] = lower_bound(Ycomp.begin(), Ycomp.end(), H[i]) - Ycomp.begin() + 1;
arr[R[i]].push_back(i);
}
for (int i = 1; i <= Q; i++) {
A[i] = lower_bound(Xcomp.begin(), Xcomp.end(), -A[i]) - Xcomp.begin() + 1;
B[i] = lower_bound(Ycomp.begin(), Ycomp.end(), B[i]) - Ycomp.begin() + 1;
queries[A[i]].push_back(i);
}
for (int i = 1; i <= SX; i++) {
for (int j : arr[i])
num[j] = query(1, 1, SY, 1, H[j] - 1) + 1;
for (int j : arr[i])
update(1, 1, SY, H[j], num[j]);
for (int j : queries[i])
ans[j] = query(1, 1, SY, 1, B[j]);
}
for (int i = 1; i <= Q; i++)
cout << ans[i] << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 11
Accepted
time: 1ms
memory: 15968kb
input:
1 1 80 22 92 52
output:
0
result:
ok single line: '0'
Test #2:
score: 11
Accepted
time: 0ms
memory: 15976kb
input:
5 1 42 48 65 49 35 82 94 73 56 6 66 91
output:
1
result:
ok single line: '1'
Test #3:
score: 11
Accepted
time: 0ms
memory: 15972kb
input:
10 1 955744818 818438338 708752654 707027641 860370925 246724418 458446623 734029097 152867387 644693269 552617712 772074081 699332741 507361150 212197996 588847946 97734740 388725575 986526630 979298764 680948105 547407644
output:
2
result:
ok single line: '2'
Test #4:
score: 11
Accepted
time: 0ms
memory: 15952kb
input:
8 1 87 58 32 42 40 31 90 2 6 88 88 51 68 61 26 51 20 44
output:
3
result:
ok single line: '3'
Test #5:
score: 11
Accepted
time: 0ms
memory: 16100kb
input:
10 1 6013 359 4321 385 8241 100 9970 721 4102 535 4062 631 845 234 2080 355 9841 211 6933 970 2170 307
output:
1
result:
ok single line: '1'
Test #6:
score: 11
Accepted
time: 1ms
memory: 16104kb
input:
10 1 495268009 115773263 299641225 13878132 805503547 154165513 974008831 46048377 205072236 730778789 279416022 745812606 803383275 232997430 114492420 714695578 918079301 281769984 987460481 287641923 740112724 849252038
output:
3
result:
ok single line: '3'
Test #7:
score: 11
Accepted
time: 1ms
memory: 16104kb
input:
10 1 202667898 195133084 994099426 992224672 329608744 319995002 851853441 854258843 200214393 204002194 78026041 69308531 904681347 910584576 322198937 320023802 823606320 829992290 90566429 95197095 487956554 993222026
output:
1
result:
ok single line: '1'
Test #8:
score: 11
Accepted
time: 1ms
memory: 16104kb
input:
10 1 5157801 984945461 675273304 329098921 127345165 873534565 956227189 34636927 578264555 419967226 264103727 738762590 123947723 879306992 251165793 739791019 514835378 494352080 103954263 892663016 897407943 957628314
output:
1
result:
ok single line: '1'
Test #9:
score: 11
Accepted
time: 0ms
memory: 16100kb
input:
10 1 234237 111 239693 90 41967 246 140601 184 218948 31 150522 218 243663 211 253761 285 243954 68 211437 264 258637 27
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Wrong Answer
time: 1ms
memory: 15932kb
input:
10 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 2 1 1 1 3 1 3
output:
1
result:
wrong answer 1st lines differ - expected: '10', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%