#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { for (const T &x : v) os << x << '\n'; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 2e9+2;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
struct event {
int x,y,c,i=-1;
bool operator<(const event& o) const {
return c > o.c or (c== o.c and i < o.i);
}
};
struct event2 {
int x,y,i=-1;
bool operator<(const event2& o) const {
return x> o.x or (x==o.x and i<o.i);
}
};
int main() {
int n,q; cin >> n >> q;
vector<event> events(n);
vector<event2> events2(n);
vector<pair<int,int>> points;
for(int i=0;i<n;++i) {
auto& e = events[i];
cin >> e.x >> e.y;
e.c = e.x+e.y;
events2[i] = {e.x,e.y,-1};
}
vi ans(q);
for(int i=0;i<q;++i) {
auto& e = events[i];
int a,b,c;
cin >> a >> b >> c;
if(c < a+b) {
events2.push_back({a,b,i});
} else {
events.push_back({a,b,c,i});
}
}
sort(all(events));
ordered_multiset sx,sy;
for(auto& e: events) {
if(e.i==-1) {
// point insertion
sx.insert(e.x);
sy.insert(e.y);
} else {
// debug(sx); debug(sy);
ans[e.i] -= sx.order_of_key(e.x);
ans[e.i] += sy.size()-sy.order_of_key(e.y);
}
}
sort(all(events2));
sy.clear();
for(auto& e: events2) {
if(e.i==-1) {
sy.insert(e.y);
} else {
ans[e.i] = sy.size()-sy.order_of_key(e.y);
}
}
cout << ans;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:43:15: warning: unused variable 'e' [-Wunused-variable]
43 | auto& e = events[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
11 ms |
876 KB |
Output is correct |
8 |
Correct |
11 ms |
876 KB |
Output is correct |
9 |
Correct |
11 ms |
876 KB |
Output is correct |
10 |
Correct |
9 ms |
876 KB |
Output is correct |
11 |
Correct |
9 ms |
876 KB |
Output is correct |
12 |
Correct |
7 ms |
748 KB |
Output is correct |
13 |
Correct |
10 ms |
876 KB |
Output is correct |
14 |
Correct |
12 ms |
876 KB |
Output is correct |
15 |
Correct |
12 ms |
876 KB |
Output is correct |
16 |
Correct |
9 ms |
876 KB |
Output is correct |
17 |
Correct |
9 ms |
876 KB |
Output is correct |
18 |
Correct |
6 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
17112 KB |
Output is correct |
2 |
Correct |
454 ms |
17112 KB |
Output is correct |
3 |
Correct |
452 ms |
17112 KB |
Output is correct |
4 |
Correct |
318 ms |
16476 KB |
Output is correct |
5 |
Correct |
344 ms |
16536 KB |
Output is correct |
6 |
Correct |
296 ms |
15744 KB |
Output is correct |
7 |
Correct |
413 ms |
17112 KB |
Output is correct |
8 |
Correct |
396 ms |
17080 KB |
Output is correct |
9 |
Correct |
395 ms |
17024 KB |
Output is correct |
10 |
Correct |
330 ms |
16216 KB |
Output is correct |
11 |
Correct |
317 ms |
16188 KB |
Output is correct |
12 |
Correct |
279 ms |
15292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
17112 KB |
Output is correct |
2 |
Correct |
454 ms |
17112 KB |
Output is correct |
3 |
Correct |
452 ms |
17112 KB |
Output is correct |
4 |
Correct |
318 ms |
16476 KB |
Output is correct |
5 |
Correct |
344 ms |
16536 KB |
Output is correct |
6 |
Correct |
296 ms |
15744 KB |
Output is correct |
7 |
Correct |
413 ms |
17112 KB |
Output is correct |
8 |
Correct |
396 ms |
17080 KB |
Output is correct |
9 |
Correct |
395 ms |
17024 KB |
Output is correct |
10 |
Correct |
330 ms |
16216 KB |
Output is correct |
11 |
Correct |
317 ms |
16188 KB |
Output is correct |
12 |
Correct |
279 ms |
15292 KB |
Output is correct |
13 |
Correct |
441 ms |
17852 KB |
Output is correct |
14 |
Correct |
433 ms |
17552 KB |
Output is correct |
15 |
Correct |
406 ms |
17240 KB |
Output is correct |
16 |
Correct |
322 ms |
16956 KB |
Output is correct |
17 |
Correct |
366 ms |
16956 KB |
Output is correct |
18 |
Correct |
293 ms |
15676 KB |
Output is correct |
19 |
Correct |
422 ms |
17852 KB |
Output is correct |
20 |
Correct |
422 ms |
17724 KB |
Output is correct |
21 |
Correct |
439 ms |
17852 KB |
Output is correct |
22 |
Correct |
327 ms |
16216 KB |
Output is correct |
23 |
Correct |
331 ms |
16444 KB |
Output is correct |
24 |
Correct |
281 ms |
15292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
11 ms |
876 KB |
Output is correct |
8 |
Correct |
11 ms |
876 KB |
Output is correct |
9 |
Correct |
11 ms |
876 KB |
Output is correct |
10 |
Correct |
9 ms |
876 KB |
Output is correct |
11 |
Correct |
9 ms |
876 KB |
Output is correct |
12 |
Correct |
7 ms |
748 KB |
Output is correct |
13 |
Correct |
10 ms |
876 KB |
Output is correct |
14 |
Correct |
12 ms |
876 KB |
Output is correct |
15 |
Correct |
12 ms |
876 KB |
Output is correct |
16 |
Correct |
9 ms |
876 KB |
Output is correct |
17 |
Correct |
9 ms |
876 KB |
Output is correct |
18 |
Correct |
6 ms |
748 KB |
Output is correct |
19 |
Correct |
426 ms |
17112 KB |
Output is correct |
20 |
Correct |
454 ms |
17112 KB |
Output is correct |
21 |
Correct |
452 ms |
17112 KB |
Output is correct |
22 |
Correct |
318 ms |
16476 KB |
Output is correct |
23 |
Correct |
344 ms |
16536 KB |
Output is correct |
24 |
Correct |
296 ms |
15744 KB |
Output is correct |
25 |
Correct |
413 ms |
17112 KB |
Output is correct |
26 |
Correct |
396 ms |
17080 KB |
Output is correct |
27 |
Correct |
395 ms |
17024 KB |
Output is correct |
28 |
Correct |
330 ms |
16216 KB |
Output is correct |
29 |
Correct |
317 ms |
16188 KB |
Output is correct |
30 |
Correct |
279 ms |
15292 KB |
Output is correct |
31 |
Correct |
441 ms |
17852 KB |
Output is correct |
32 |
Correct |
433 ms |
17552 KB |
Output is correct |
33 |
Correct |
406 ms |
17240 KB |
Output is correct |
34 |
Correct |
322 ms |
16956 KB |
Output is correct |
35 |
Correct |
366 ms |
16956 KB |
Output is correct |
36 |
Correct |
293 ms |
15676 KB |
Output is correct |
37 |
Correct |
422 ms |
17852 KB |
Output is correct |
38 |
Correct |
422 ms |
17724 KB |
Output is correct |
39 |
Correct |
439 ms |
17852 KB |
Output is correct |
40 |
Correct |
327 ms |
16216 KB |
Output is correct |
41 |
Correct |
331 ms |
16444 KB |
Output is correct |
42 |
Correct |
281 ms |
15292 KB |
Output is correct |
43 |
Correct |
508 ms |
19772 KB |
Output is correct |
44 |
Correct |
482 ms |
19644 KB |
Output is correct |
45 |
Correct |
482 ms |
19644 KB |
Output is correct |
46 |
Correct |
396 ms |
18156 KB |
Output is correct |
47 |
Correct |
405 ms |
18108 KB |
Output is correct |
48 |
Correct |
275 ms |
15804 KB |
Output is correct |
49 |
Correct |
485 ms |
19556 KB |
Output is correct |
50 |
Correct |
476 ms |
19644 KB |
Output is correct |
51 |
Correct |
528 ms |
19644 KB |
Output is correct |
52 |
Correct |
444 ms |
17980 KB |
Output is correct |
53 |
Correct |
356 ms |
16984 KB |
Output is correct |