#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;
typedef pair<int, int> pi;
const int N = 7e5 + 5;
map<int, int> mp;
template<class T> using Tree = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
void compress() {
int curr = 0;
for (auto& p : mp) {
p.second = ++curr;
}
assert(curr < N);
}
template<int SZ> struct mstree {
Tree<pi> val[SZ + 1]; // for offline queries use vector with binary search instead
void upd(int x, int y, int t = 1) { // x-coordinate between 1 and SZ inclusive
for (int X = x; X <= SZ; X += X & -X) {
if (t == 1)
val[X].insert( { y, x });
else
val[X].erase( { y, x });
}
}
int query(int x, int y) {
assert(x >= 0 && y >= 0);
int t = 0;
for (; x > 0; x -= x & -x)
t += val[x].order_of_key( { y, N });
return t;
}
int query(int lox, int hix, int loy, int hiy) { // query number of elements within a rectangle
return query(hix, hiy) - query(lox - 1, hiy) - query(hix, loy - 1)
+ query(lox - 1, loy - 1);
}
};
mstree<N> bit;
struct Score {
int x, y;
int sum;
bool operator<(const Score& other) const {
return sum < other.sum;
}
};
struct Query {
int x, y, z;
int ind;
int res;
bool operator<(const Query& other) const {
return z < other.z;
}
};
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cerr.tie(0);
#ifdef Local
freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif
int n, q;
cin >> n >> q;
vector<Score> scores(n);
vector<Query> queries(q);
for (auto& score : scores) {
cin >> score.x >> score.y;
score.sum = score.x + score.y;
mp[score.x];
mp[score.y];
mp[score.sum];
}
for (int i = 0; i < q; ++i) {
auto& query = queries[i];
cin >> query.x >> query.y >> query.z;
mp[query.x];
mp[query.y];
mp[query.z];
query.ind = i;
}
compress();
for (auto& score : scores) {
score.x = mp[score.x];
score.y = mp[score.y];
score.sum = mp[score.sum];
}
for (auto& query : queries) {
query.x = mp[query.x];
query.y = mp[query.y];
query.z = mp[query.z];
}
sort(scores.begin(), scores.end());
sort(queries.rbegin(), queries.rend());
for (auto& query : queries) {
while (!scores.empty() && scores.back().sum >= query.z) {
bit.upd(scores.back().x, scores.back().y);
scores.pop_back();
}
query.res = bit.query(query.x, N, query.y, N);
}
sort(queries.begin(), queries.end(), [](const Query& a , const Query& b) {
return a.ind < b.ind;
});
for (auto& query : queries) {
cout << query.res << endl;
}
}
Compilation message
examination.cpp:5:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/STACK:1024000000,1024000000")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
66168 KB |
Output is correct |
2 |
Correct |
86 ms |
66236 KB |
Output is correct |
3 |
Correct |
86 ms |
66168 KB |
Output is correct |
4 |
Correct |
85 ms |
66140 KB |
Output is correct |
5 |
Correct |
86 ms |
66168 KB |
Output is correct |
6 |
Correct |
88 ms |
66168 KB |
Output is correct |
7 |
Correct |
120 ms |
69496 KB |
Output is correct |
8 |
Correct |
117 ms |
69500 KB |
Output is correct |
9 |
Correct |
118 ms |
69624 KB |
Output is correct |
10 |
Correct |
113 ms |
69240 KB |
Output is correct |
11 |
Correct |
117 ms |
70264 KB |
Output is correct |
12 |
Correct |
109 ms |
69840 KB |
Output is correct |
13 |
Correct |
118 ms |
69368 KB |
Output is correct |
14 |
Correct |
116 ms |
69368 KB |
Output is correct |
15 |
Correct |
119 ms |
69556 KB |
Output is correct |
16 |
Correct |
130 ms |
70268 KB |
Output is correct |
17 |
Correct |
113 ms |
69112 KB |
Output is correct |
18 |
Correct |
125 ms |
70008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2620 ms |
150364 KB |
Output is correct |
2 |
Correct |
2546 ms |
150520 KB |
Output is correct |
3 |
Correct |
2537 ms |
150468 KB |
Output is correct |
4 |
Correct |
1879 ms |
149112 KB |
Output is correct |
5 |
Correct |
1655 ms |
191648 KB |
Output is correct |
6 |
Correct |
1582 ms |
186404 KB |
Output is correct |
7 |
Correct |
2093 ms |
152416 KB |
Output is correct |
8 |
Correct |
2411 ms |
152640 KB |
Output is correct |
9 |
Correct |
1818 ms |
152704 KB |
Output is correct |
10 |
Correct |
1522 ms |
200824 KB |
Output is correct |
11 |
Correct |
1361 ms |
150644 KB |
Output is correct |
12 |
Correct |
2485 ms |
195904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2620 ms |
150364 KB |
Output is correct |
2 |
Correct |
2546 ms |
150520 KB |
Output is correct |
3 |
Correct |
2537 ms |
150468 KB |
Output is correct |
4 |
Correct |
1879 ms |
149112 KB |
Output is correct |
5 |
Correct |
1655 ms |
191648 KB |
Output is correct |
6 |
Correct |
1582 ms |
186404 KB |
Output is correct |
7 |
Correct |
2093 ms |
152416 KB |
Output is correct |
8 |
Correct |
2411 ms |
152640 KB |
Output is correct |
9 |
Correct |
1818 ms |
152704 KB |
Output is correct |
10 |
Correct |
1522 ms |
200824 KB |
Output is correct |
11 |
Correct |
1361 ms |
150644 KB |
Output is correct |
12 |
Correct |
2485 ms |
195904 KB |
Output is correct |
13 |
Correct |
2332 ms |
153436 KB |
Output is correct |
14 |
Correct |
2703 ms |
152472 KB |
Output is correct |
15 |
Correct |
2594 ms |
152308 KB |
Output is correct |
16 |
Correct |
1631 ms |
150644 KB |
Output is correct |
17 |
Correct |
1718 ms |
192020 KB |
Output is correct |
18 |
Correct |
1568 ms |
186624 KB |
Output is correct |
19 |
Correct |
2641 ms |
153752 KB |
Output is correct |
20 |
Correct |
2637 ms |
152968 KB |
Output is correct |
21 |
Correct |
2162 ms |
153416 KB |
Output is correct |
22 |
Correct |
1525 ms |
200884 KB |
Output is correct |
23 |
Correct |
1391 ms |
150804 KB |
Output is correct |
24 |
Correct |
2496 ms |
195960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
66168 KB |
Output is correct |
2 |
Correct |
86 ms |
66236 KB |
Output is correct |
3 |
Correct |
86 ms |
66168 KB |
Output is correct |
4 |
Correct |
85 ms |
66140 KB |
Output is correct |
5 |
Correct |
86 ms |
66168 KB |
Output is correct |
6 |
Correct |
88 ms |
66168 KB |
Output is correct |
7 |
Correct |
120 ms |
69496 KB |
Output is correct |
8 |
Correct |
117 ms |
69500 KB |
Output is correct |
9 |
Correct |
118 ms |
69624 KB |
Output is correct |
10 |
Correct |
113 ms |
69240 KB |
Output is correct |
11 |
Correct |
117 ms |
70264 KB |
Output is correct |
12 |
Correct |
109 ms |
69840 KB |
Output is correct |
13 |
Correct |
118 ms |
69368 KB |
Output is correct |
14 |
Correct |
116 ms |
69368 KB |
Output is correct |
15 |
Correct |
119 ms |
69556 KB |
Output is correct |
16 |
Correct |
130 ms |
70268 KB |
Output is correct |
17 |
Correct |
113 ms |
69112 KB |
Output is correct |
18 |
Correct |
125 ms |
70008 KB |
Output is correct |
19 |
Correct |
2620 ms |
150364 KB |
Output is correct |
20 |
Correct |
2546 ms |
150520 KB |
Output is correct |
21 |
Correct |
2537 ms |
150468 KB |
Output is correct |
22 |
Correct |
1879 ms |
149112 KB |
Output is correct |
23 |
Correct |
1655 ms |
191648 KB |
Output is correct |
24 |
Correct |
1582 ms |
186404 KB |
Output is correct |
25 |
Correct |
2093 ms |
152416 KB |
Output is correct |
26 |
Correct |
2411 ms |
152640 KB |
Output is correct |
27 |
Correct |
1818 ms |
152704 KB |
Output is correct |
28 |
Correct |
1522 ms |
200824 KB |
Output is correct |
29 |
Correct |
1361 ms |
150644 KB |
Output is correct |
30 |
Correct |
2485 ms |
195904 KB |
Output is correct |
31 |
Correct |
2332 ms |
153436 KB |
Output is correct |
32 |
Correct |
2703 ms |
152472 KB |
Output is correct |
33 |
Correct |
2594 ms |
152308 KB |
Output is correct |
34 |
Correct |
1631 ms |
150644 KB |
Output is correct |
35 |
Correct |
1718 ms |
192020 KB |
Output is correct |
36 |
Correct |
1568 ms |
186624 KB |
Output is correct |
37 |
Correct |
2641 ms |
153752 KB |
Output is correct |
38 |
Correct |
2637 ms |
152968 KB |
Output is correct |
39 |
Correct |
2162 ms |
153416 KB |
Output is correct |
40 |
Correct |
1525 ms |
200884 KB |
Output is correct |
41 |
Correct |
1391 ms |
150804 KB |
Output is correct |
42 |
Correct |
2496 ms |
195960 KB |
Output is correct |
43 |
Correct |
2932 ms |
166752 KB |
Output is correct |
44 |
Correct |
2890 ms |
166712 KB |
Output is correct |
45 |
Execution timed out |
3054 ms |
165444 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |