# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
49783 |
2018-06-03T06:18:34 Z |
강태규(#1279, imeimi2000) |
None (JOI16_matryoshka) |
C++11 |
|
496 ms |
10556 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
const int MAXN = 2e5 + 1;
const int inf = 1e9 + 7;
struct mat {
int r, h, i;
void scan(int idx) {
i = idx;
scanf("%d%d", &r, &h);
}
bool operator<(const mat &x) const {
return r > x.r;
}
};
int n, q, m;
mat arr[MAXN];
mat qs[MAXN];
int ans[MAXN];
int comp[MAXN];
int seg[1 << 19];
void update(int i, int s, int e, int x, int v) {
seg[i] += v;
if (s == e) return;
int m = (s + e) / 2;
if (x <= comp[m]) update(i << 1, s, m, x, v);
else update(i << 1 | 1, m + 1, e, x, v);
}
int query(int i, int s, int e, int x) {
if (comp[e] < x) return 0;
if (x <= comp[s]) return seg[i];
int m = (s + e) / 2;
return query(i << 1, s, m, x) + query(i << 1 | 1, m + 1, e, x);
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 0; i < n; ++i) {
arr[i].scan(i);
comp[i] = arr[i].h;
}
sort(arr, arr + n);
sort(comp, comp + n);
m = unique(comp, comp + n) - comp;
for (int i = 0; i < q; ++i) {
qs[i].scan(i);
}
sort(qs, qs + q);
multiset<int> mp;
multiset<int>::iterator it;
int cnt = 0;
for (int i = 0, j = 0; i < q; ++i) {
for (; j < n && qs[i].r <= arr[j].r; ++j) {
update(1, 0, m - 1, arr[j].h, -1);
if (j && arr[j].r != arr[j - 1].r) {
for (int k = j - 1; 0 <= k && arr[j - 1].r == arr[k].r; --k) {
mp.insert(arr[k].h);
}
}
it = mp.upper_bound(arr[j].h);
if (it != mp.end()) {
++cnt;
update(1, 0, m - 1, *it, 1);
mp.erase(it);
}
}
ans[qs[i].i] = j - cnt + query(1, 0, m - 1, qs[i].h + 1);
}
for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~
matryoshka.cpp: In member function 'void mat::scan(int)':
matryoshka.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &r, &h);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
4 ms |
724 KB |
Output is correct |
23 |
Correct |
6 ms |
724 KB |
Output is correct |
24 |
Correct |
6 ms |
724 KB |
Output is correct |
25 |
Correct |
7 ms |
748 KB |
Output is correct |
26 |
Correct |
6 ms |
748 KB |
Output is correct |
27 |
Correct |
5 ms |
748 KB |
Output is correct |
28 |
Correct |
7 ms |
748 KB |
Output is correct |
29 |
Correct |
5 ms |
800 KB |
Output is correct |
30 |
Correct |
5 ms |
800 KB |
Output is correct |
31 |
Correct |
5 ms |
800 KB |
Output is correct |
32 |
Correct |
7 ms |
800 KB |
Output is correct |
33 |
Correct |
6 ms |
800 KB |
Output is correct |
34 |
Correct |
5 ms |
800 KB |
Output is correct |
35 |
Correct |
6 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
428 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
4 ms |
724 KB |
Output is correct |
23 |
Correct |
6 ms |
724 KB |
Output is correct |
24 |
Correct |
6 ms |
724 KB |
Output is correct |
25 |
Correct |
7 ms |
748 KB |
Output is correct |
26 |
Correct |
6 ms |
748 KB |
Output is correct |
27 |
Correct |
5 ms |
748 KB |
Output is correct |
28 |
Correct |
7 ms |
748 KB |
Output is correct |
29 |
Correct |
5 ms |
800 KB |
Output is correct |
30 |
Correct |
5 ms |
800 KB |
Output is correct |
31 |
Correct |
5 ms |
800 KB |
Output is correct |
32 |
Correct |
7 ms |
800 KB |
Output is correct |
33 |
Correct |
6 ms |
800 KB |
Output is correct |
34 |
Correct |
5 ms |
800 KB |
Output is correct |
35 |
Correct |
6 ms |
800 KB |
Output is correct |
36 |
Correct |
411 ms |
8776 KB |
Output is correct |
37 |
Correct |
308 ms |
8776 KB |
Output is correct |
38 |
Correct |
126 ms |
8776 KB |
Output is correct |
39 |
Correct |
244 ms |
8776 KB |
Output is correct |
40 |
Correct |
263 ms |
9148 KB |
Output is correct |
41 |
Correct |
322 ms |
9148 KB |
Output is correct |
42 |
Correct |
188 ms |
9764 KB |
Output is correct |
43 |
Correct |
108 ms |
9764 KB |
Output is correct |
44 |
Correct |
437 ms |
9848 KB |
Output is correct |
45 |
Correct |
446 ms |
9848 KB |
Output is correct |
46 |
Correct |
483 ms |
9848 KB |
Output is correct |
47 |
Correct |
424 ms |
9848 KB |
Output is correct |
48 |
Correct |
496 ms |
10448 KB |
Output is correct |
49 |
Correct |
487 ms |
10448 KB |
Output is correct |
50 |
Correct |
427 ms |
10556 KB |
Output is correct |