# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
557299 | 2022-05-05T05:51:36 Z | Ai7081 | Examination (JOI19_examination) | C++17 | 1947 ms | 124040 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct query{ int x, y, z, idx; bool operator < (const query &o) const {return z > o.z;} }; struct score{ int a, b; bool operator < (const score &o) const {return a+b > o.a+o.b;} }; int n, t, fenA[N], fenB[N], timer, now, ans[N]; score s[N]; query q[N]; vector<int> fen[N]; set<int> fen_st[N], A, B; map<int, int> mpA, mpB, mp_fen[N]; void add_set(int i, int val) { for (; i<N; i+=i&(-i)) fen_st[i].insert(val); } void add(int idx) { int i = mpA[s[idx].a]; for (; i<=A.size(); i+=i&(-i)) { fenA[i]++; int j = mp_fen[i][s[idx].b]; for (; j<=mp_fen[i].size(); j+=j&(-j)) fen[i][j]++; } i = mpB[s[idx].b]; for (; i<=B.size(); i+=i&(-i)) fenB[i]++; } int query(int x, int y) { int ret = now; auto it = mpA.lower_bound(x); if (it != mpA.begin()) { int i = mpA[(--it)->first]; for (; i>0; i-=i&(-i)) { ret -= fenA[i]; it = mp_fen[i].lower_bound(y); if (it != mp_fen[i].begin()) { int j = mp_fen[i][(--it)->first]; for (; j>0; j-=j&(-j)) ret += fen[i][j]; } } } it = mpB.lower_bound(y); if (it != mpB.begin()) { int i = mpB[(--it)->first]; for (; i>0; i-=i&(-i)) ret -= fenB[i]; } return ret; } int main() { scanf(" %d %d", &n, &t); for (int i=0; i<n; i++) scanf(" %d %d", &s[i].a, &s[i].b); for (int i=0; i<t; i++) scanf(" %d %d %d", &q[i].x, &q[i].y, &q[i].z), q[i].idx = i; sort(s, s+n); sort(q, q+t); // build fenwick tree for (int i=0; i<n; i++) A.insert(s[i].a), B.insert(s[i].b); timer = 0; for (auto it : A) mpA[it] = ++timer; timer = 0 ; for (auto it : B) mpB[it] = ++timer; for (int i=0; i<n; i++) add_set(mpA[s[i].a], s[i].b); for (int i=1; i<=mpA.size(); i++) { fen[i].assign(fen_st[i].size()+5, 0); timer = 0; for (auto it : fen_st[i]) mp_fen[i][it] = ++timer; } // do query for (int i=0; i<t; i++) { while (now < n && s[now].a + s[now].b >= q[i].z) add(now++); ans[q[i].idx] = query(q[i].x, q[i].y); } for (int i=0; i<n; i++) printf("%d\n", ans[i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 6 ms | 11988 KB | Output is correct |
3 | Correct | 6 ms | 12080 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 11988 KB | Output is correct |
6 | Correct | 7 ms | 11976 KB | Output is correct |
7 | Correct | 23 ms | 15316 KB | Output is correct |
8 | Correct | 24 ms | 15360 KB | Output is correct |
9 | Correct | 25 ms | 15368 KB | Output is correct |
10 | Correct | 12 ms | 13140 KB | Output is correct |
11 | Correct | 21 ms | 14968 KB | Output is correct |
12 | Correct | 9 ms | 12116 KB | Output is correct |
13 | Correct | 26 ms | 15236 KB | Output is correct |
14 | Correct | 24 ms | 15380 KB | Output is correct |
15 | Correct | 23 ms | 15324 KB | Output is correct |
16 | Correct | 17 ms | 14996 KB | Output is correct |
17 | Correct | 11 ms | 12756 KB | Output is correct |
18 | Correct | 8 ms | 12108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1677 ms | 109572 KB | Output is correct |
2 | Correct | 1687 ms | 109384 KB | Output is correct |
3 | Correct | 1689 ms | 109472 KB | Output is correct |
4 | Correct | 293 ms | 43396 KB | Output is correct |
5 | Correct | 739 ms | 79168 KB | Output is correct |
6 | Correct | 88 ms | 15308 KB | Output is correct |
7 | Correct | 1252 ms | 109504 KB | Output is correct |
8 | Correct | 1365 ms | 109488 KB | Output is correct |
9 | Correct | 1143 ms | 109436 KB | Output is correct |
10 | Correct | 513 ms | 75044 KB | Output is correct |
11 | Correct | 186 ms | 29244 KB | Output is correct |
12 | Correct | 64 ms | 14896 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1677 ms | 109572 KB | Output is correct |
2 | Correct | 1687 ms | 109384 KB | Output is correct |
3 | Correct | 1689 ms | 109472 KB | Output is correct |
4 | Correct | 293 ms | 43396 KB | Output is correct |
5 | Correct | 739 ms | 79168 KB | Output is correct |
6 | Correct | 88 ms | 15308 KB | Output is correct |
7 | Correct | 1252 ms | 109504 KB | Output is correct |
8 | Correct | 1365 ms | 109488 KB | Output is correct |
9 | Correct | 1143 ms | 109436 KB | Output is correct |
10 | Correct | 513 ms | 75044 KB | Output is correct |
11 | Correct | 186 ms | 29244 KB | Output is correct |
12 | Correct | 64 ms | 14896 KB | Output is correct |
13 | Correct | 1792 ms | 109380 KB | Output is correct |
14 | Correct | 1757 ms | 109476 KB | Output is correct |
15 | Correct | 1626 ms | 109600 KB | Output is correct |
16 | Correct | 314 ms | 43468 KB | Output is correct |
17 | Correct | 749 ms | 79144 KB | Output is correct |
18 | Correct | 89 ms | 15308 KB | Output is correct |
19 | Correct | 1757 ms | 109556 KB | Output is correct |
20 | Correct | 1787 ms | 109504 KB | Output is correct |
21 | Correct | 1525 ms | 109548 KB | Output is correct |
22 | Correct | 511 ms | 75260 KB | Output is correct |
23 | Correct | 188 ms | 29152 KB | Output is correct |
24 | Correct | 63 ms | 14928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 6 ms | 11988 KB | Output is correct |
3 | Correct | 6 ms | 12080 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 11988 KB | Output is correct |
6 | Correct | 7 ms | 11976 KB | Output is correct |
7 | Correct | 23 ms | 15316 KB | Output is correct |
8 | Correct | 24 ms | 15360 KB | Output is correct |
9 | Correct | 25 ms | 15368 KB | Output is correct |
10 | Correct | 12 ms | 13140 KB | Output is correct |
11 | Correct | 21 ms | 14968 KB | Output is correct |
12 | Correct | 9 ms | 12116 KB | Output is correct |
13 | Correct | 26 ms | 15236 KB | Output is correct |
14 | Correct | 24 ms | 15380 KB | Output is correct |
15 | Correct | 23 ms | 15324 KB | Output is correct |
16 | Correct | 17 ms | 14996 KB | Output is correct |
17 | Correct | 11 ms | 12756 KB | Output is correct |
18 | Correct | 8 ms | 12108 KB | Output is correct |
19 | Correct | 1677 ms | 109572 KB | Output is correct |
20 | Correct | 1687 ms | 109384 KB | Output is correct |
21 | Correct | 1689 ms | 109472 KB | Output is correct |
22 | Correct | 293 ms | 43396 KB | Output is correct |
23 | Correct | 739 ms | 79168 KB | Output is correct |
24 | Correct | 88 ms | 15308 KB | Output is correct |
25 | Correct | 1252 ms | 109504 KB | Output is correct |
26 | Correct | 1365 ms | 109488 KB | Output is correct |
27 | Correct | 1143 ms | 109436 KB | Output is correct |
28 | Correct | 513 ms | 75044 KB | Output is correct |
29 | Correct | 186 ms | 29244 KB | Output is correct |
30 | Correct | 64 ms | 14896 KB | Output is correct |
31 | Correct | 1792 ms | 109380 KB | Output is correct |
32 | Correct | 1757 ms | 109476 KB | Output is correct |
33 | Correct | 1626 ms | 109600 KB | Output is correct |
34 | Correct | 314 ms | 43468 KB | Output is correct |
35 | Correct | 749 ms | 79144 KB | Output is correct |
36 | Correct | 89 ms | 15308 KB | Output is correct |
37 | Correct | 1757 ms | 109556 KB | Output is correct |
38 | Correct | 1787 ms | 109504 KB | Output is correct |
39 | Correct | 1525 ms | 109548 KB | Output is correct |
40 | Correct | 511 ms | 75260 KB | Output is correct |
41 | Correct | 188 ms | 29152 KB | Output is correct |
42 | Correct | 63 ms | 14928 KB | Output is correct |
43 | Correct | 1947 ms | 124040 KB | Output is correct |
44 | Correct | 1940 ms | 124020 KB | Output is correct |
45 | Correct | 1922 ms | 123920 KB | Output is correct |
46 | Correct | 368 ms | 51684 KB | Output is correct |
47 | Correct | 979 ms | 108828 KB | Output is correct |
48 | Correct | 88 ms | 15012 KB | Output is correct |
49 | Correct | 1528 ms | 123984 KB | Output is correct |
50 | Correct | 1767 ms | 123912 KB | Output is correct |
51 | Correct | 1418 ms | 123924 KB | Output is correct |
52 | Correct | 690 ms | 109756 KB | Output is correct |
53 | Correct | 248 ms | 37464 KB | Output is correct |