#pragma GCC optimize("Ofast")
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
typedef tree<pair<pair<int, int>, int>, null_type, less<pair<pair<int, int>, int> >, rb_tree_tag, tree_order_statistics_node_update> OST;
#define int long long
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
OST bit[MAXN]; // 2D bit in regular matrices but only supporting single add/del
int id = 0;
map<pair<int, int>, queue<int> > mp;
void insert(int x, int y) {
id++;
mp[{y, x}].push(id);
for(;x<MAXN;x+=x&-x) bit[x].insert({{y, x}, id});
}
void erase(int x, int y) {
int ono = mp[{y, x}].front(); mp[{y, x}].pop();
for(;x<MAXN;x+=x&-x) bit[x].erase({{y, x}, ono});
}
int query(int x, int y) {
int sum = 0;
for(;x;x-=x&-x) sum += bit[x].order_of_key({{y+1, 0}, 0});
return sum;
}
struct event {
int type; // type = 0: "insert", type > 0: "query"
int a, b, c;
};
bool cmp(event x, event y) {
if(x.c == y.c) return x.type < y.type;
return x.c > y.c;
}
void solve(int tc) {
int n, q;
cin >> n >> q;
event e[n + q + 1];
set<int> s;
for(int i=1; i<=n; i++) {
e[i].type = 0;
cin >> e[i].a >> e[i].b;
e[i].c = e[i].a + e[i].b;
s.insert(e[i].a);
s.insert(e[i].b);
s.insert(e[i].c);
}
for(int i=1; i<=q; i++) {
e[n+i].type = i;
cin >> e[n+i].a >> e[n+i].b >> e[n+i].c;
s.insert(e[n+i].a);
s.insert(e[n+i].b);
s.insert(e[n+i].c);
}
int nxt = 0;
unordered_map<int, int> is;
for(int x: s) {
is[x] = ++nxt;
}
for(int i=1; i<=n+q; i++) {
e[i].a = is[e[i].a];
e[i].b = is[e[i].b];
e[i].c = is[e[i].c];
}
sort(e + 1, e+n+q + 1, cmp);
int ans[q+1];
for(int i=1; i<=n+q; i++) {
if(e[i].type == 0) {
insert(e[i].a + 1, e[i].b + 1);
}
else {
ans[e[i].type] = query(300000, 300000) - query(300000, e[i].b)
- query(e[i].a, 300000) + query(e[i].a, e[i].b);
}
}
for(int i=1; i<=q; i++) {
cout << ans[i] << "\n";
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
28492 KB |
Output is correct |
2 |
Correct |
21 ms |
28428 KB |
Output is correct |
3 |
Correct |
21 ms |
28492 KB |
Output is correct |
4 |
Correct |
28 ms |
28552 KB |
Output is correct |
5 |
Correct |
23 ms |
28492 KB |
Output is correct |
6 |
Correct |
22 ms |
28524 KB |
Output is correct |
7 |
Correct |
44 ms |
34904 KB |
Output is correct |
8 |
Correct |
46 ms |
34880 KB |
Output is correct |
9 |
Correct |
46 ms |
34936 KB |
Output is correct |
10 |
Correct |
43 ms |
34440 KB |
Output is correct |
11 |
Correct |
47 ms |
35284 KB |
Output is correct |
12 |
Correct |
40 ms |
31948 KB |
Output is correct |
13 |
Correct |
43 ms |
34672 KB |
Output is correct |
14 |
Correct |
46 ms |
34712 KB |
Output is correct |
15 |
Correct |
46 ms |
34628 KB |
Output is correct |
16 |
Correct |
44 ms |
34920 KB |
Output is correct |
17 |
Correct |
41 ms |
34132 KB |
Output is correct |
18 |
Correct |
38 ms |
32128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1842 ms |
189500 KB |
Output is correct |
2 |
Correct |
1882 ms |
189496 KB |
Output is correct |
3 |
Correct |
1860 ms |
189596 KB |
Output is correct |
4 |
Correct |
1388 ms |
183424 KB |
Output is correct |
5 |
Correct |
1195 ms |
222772 KB |
Output is correct |
6 |
Correct |
978 ms |
144612 KB |
Output is correct |
7 |
Correct |
1398 ms |
189492 KB |
Output is correct |
8 |
Correct |
1715 ms |
189628 KB |
Output is correct |
9 |
Correct |
1282 ms |
189780 KB |
Output is correct |
10 |
Correct |
1043 ms |
203196 KB |
Output is correct |
11 |
Correct |
1033 ms |
159560 KB |
Output is correct |
12 |
Correct |
855 ms |
149304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1842 ms |
189500 KB |
Output is correct |
2 |
Correct |
1882 ms |
189496 KB |
Output is correct |
3 |
Correct |
1860 ms |
189596 KB |
Output is correct |
4 |
Correct |
1388 ms |
183424 KB |
Output is correct |
5 |
Correct |
1195 ms |
222772 KB |
Output is correct |
6 |
Correct |
978 ms |
144612 KB |
Output is correct |
7 |
Correct |
1398 ms |
189492 KB |
Output is correct |
8 |
Correct |
1715 ms |
189628 KB |
Output is correct |
9 |
Correct |
1282 ms |
189780 KB |
Output is correct |
10 |
Correct |
1043 ms |
203196 KB |
Output is correct |
11 |
Correct |
1033 ms |
159560 KB |
Output is correct |
12 |
Correct |
855 ms |
149304 KB |
Output is correct |
13 |
Correct |
1657 ms |
191476 KB |
Output is correct |
14 |
Correct |
1867 ms |
189628 KB |
Output is correct |
15 |
Correct |
1853 ms |
189492 KB |
Output is correct |
16 |
Correct |
1093 ms |
183448 KB |
Output is correct |
17 |
Correct |
1157 ms |
223024 KB |
Output is correct |
18 |
Correct |
966 ms |
144576 KB |
Output is correct |
19 |
Correct |
1629 ms |
191428 KB |
Output is correct |
20 |
Correct |
1745 ms |
190632 KB |
Output is correct |
21 |
Correct |
1528 ms |
191336 KB |
Output is correct |
22 |
Correct |
1053 ms |
203472 KB |
Output is correct |
23 |
Correct |
1025 ms |
159252 KB |
Output is correct |
24 |
Correct |
840 ms |
149188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
28492 KB |
Output is correct |
2 |
Correct |
21 ms |
28428 KB |
Output is correct |
3 |
Correct |
21 ms |
28492 KB |
Output is correct |
4 |
Correct |
28 ms |
28552 KB |
Output is correct |
5 |
Correct |
23 ms |
28492 KB |
Output is correct |
6 |
Correct |
22 ms |
28524 KB |
Output is correct |
7 |
Correct |
44 ms |
34904 KB |
Output is correct |
8 |
Correct |
46 ms |
34880 KB |
Output is correct |
9 |
Correct |
46 ms |
34936 KB |
Output is correct |
10 |
Correct |
43 ms |
34440 KB |
Output is correct |
11 |
Correct |
47 ms |
35284 KB |
Output is correct |
12 |
Correct |
40 ms |
31948 KB |
Output is correct |
13 |
Correct |
43 ms |
34672 KB |
Output is correct |
14 |
Correct |
46 ms |
34712 KB |
Output is correct |
15 |
Correct |
46 ms |
34628 KB |
Output is correct |
16 |
Correct |
44 ms |
34920 KB |
Output is correct |
17 |
Correct |
41 ms |
34132 KB |
Output is correct |
18 |
Correct |
38 ms |
32128 KB |
Output is correct |
19 |
Correct |
1842 ms |
189500 KB |
Output is correct |
20 |
Correct |
1882 ms |
189496 KB |
Output is correct |
21 |
Correct |
1860 ms |
189596 KB |
Output is correct |
22 |
Correct |
1388 ms |
183424 KB |
Output is correct |
23 |
Correct |
1195 ms |
222772 KB |
Output is correct |
24 |
Correct |
978 ms |
144612 KB |
Output is correct |
25 |
Correct |
1398 ms |
189492 KB |
Output is correct |
26 |
Correct |
1715 ms |
189628 KB |
Output is correct |
27 |
Correct |
1282 ms |
189780 KB |
Output is correct |
28 |
Correct |
1043 ms |
203196 KB |
Output is correct |
29 |
Correct |
1033 ms |
159560 KB |
Output is correct |
30 |
Correct |
855 ms |
149304 KB |
Output is correct |
31 |
Correct |
1657 ms |
191476 KB |
Output is correct |
32 |
Correct |
1867 ms |
189628 KB |
Output is correct |
33 |
Correct |
1853 ms |
189492 KB |
Output is correct |
34 |
Correct |
1093 ms |
183448 KB |
Output is correct |
35 |
Correct |
1157 ms |
223024 KB |
Output is correct |
36 |
Correct |
966 ms |
144576 KB |
Output is correct |
37 |
Correct |
1629 ms |
191428 KB |
Output is correct |
38 |
Correct |
1745 ms |
190632 KB |
Output is correct |
39 |
Correct |
1528 ms |
191336 KB |
Output is correct |
40 |
Correct |
1053 ms |
203472 KB |
Output is correct |
41 |
Correct |
1025 ms |
159252 KB |
Output is correct |
42 |
Correct |
840 ms |
149188 KB |
Output is correct |
43 |
Runtime error |
801 ms |
183444 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |