#include <bits/stdc++.h>
//#include <bits/debug.hpp>
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Examination"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 6e5 + 7
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r)(rng);
}
int n, q;
vector<ll> Val;
int ans[maxn], res[maxn];
struct dl {
ll x, y, z, id;
} qr[maxn];
struct BIT {
vector<int> bit[maxn], nodes[maxn];
void init(vector<pair<int, int>> P) {
sort(all(P), [](pair<int, int> x, pair<int, int> y) { return x.second < y.second; });
for(auto [x, y] : P) {
for(int u = x; u < maxn; u += (u & -u)) {
if(nodes[u].empty() || nodes[u].back() != y) nodes[u].push_back(y);
}
}
fi(i, 1, maxn - 2) bit[i].resize(nodes[i].size() + 5);
}
int GetID(int x, int val) {
return upper_bound(all(nodes[x]), val) - nodes[x].begin();
}
void update(int u, int v) {
for(int x = u; x < maxn; x += (x & -x))
for(int y = GetID(x, v); y < bit[x].size(); y += (y & -y)) {
bit[x][y] ++;
}
}
int get(int u, int v, int ans = 0) {
for(int x = u; x > 0; x -= (x & -x))
for(int y = GetID(x, v); y > 0; y -= (y & -y)) {
ans += bit[x][y];
}
return ans;
}
int get(int x, int y, int u, int v) {
return get(u, v) - get(u, y - 1) - get(x - 1, v) + get(x - 1, y - 1);
}
} Bit;
void solve()
{
cin >> n >> q;
fi(i, 1, n + q) {
if(i <= n) cin >> qr[i].x >> qr[i].y, qr[i].z = qr[i].x + qr[i].y;
else cin >> qr[i].x >> qr[i].y >> qr[i].z;
qr[i].id = (i > n) ? i - n : -i;
Val.push_back(qr[i].x);
Val.push_back(qr[i].y);
Val.push_back(qr[i].z);
}
resp(Val);
int N = Val.size();
auto getv = [&](ll x) {
return upper_bound(all(Val), x) - Val.begin();
};
vector<pair<int, int>> todo;
fi(i, 1, n + q) {
qr[i].x = getv(qr[i].x);
qr[i].y = getv(qr[i].y);
qr[i].z = getv(qr[i].z);
if(i <= n) todo.push_back({qr[i].y, qr[i].z});
}
Bit.init(todo);
sort(qr + 1, qr + 1 + n + q, [](dl x, dl y) {
if(x.x == y.x) return x.id < y.id;
return x.x > y.x;
} );
fi(i, 1, n + q) {
int x = qr[i].x, y = qr[i].y, z = qr[i].z, id = qr[i].id;
if(id < 0) Bit.update(y, z);
else ans[id] = Bit.get(y, z, N, N);
}
fi(i, 1, q) cout << ans[i] << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
examination.cpp: In member function 'void BIT::update(int, int)':
examination.cpp:53:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int y = GetID(x, v); y < bit[x].size(); y += (y & -y)) {
| ~~^~~~~~~~~~~~~~~
examination.cpp: In function 'void solve()':
examination.cpp:112:13: warning: unused variable 'x' [-Wunused-variable]
112 | int x = qr[i].x, y = qr[i].y, z = qr[i].z, id = qr[i].id;
| ^
examination.cpp: In function 'int main()':
examination.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
131 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:132:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
132 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
50152 KB |
Output is correct |
2 |
Correct |
30 ms |
50000 KB |
Output is correct |
3 |
Correct |
27 ms |
50012 KB |
Output is correct |
4 |
Correct |
27 ms |
50012 KB |
Output is correct |
5 |
Correct |
29 ms |
50012 KB |
Output is correct |
6 |
Correct |
37 ms |
50004 KB |
Output is correct |
7 |
Correct |
47 ms |
50904 KB |
Output is correct |
8 |
Correct |
36 ms |
50900 KB |
Output is correct |
9 |
Correct |
40 ms |
50904 KB |
Output is correct |
10 |
Correct |
41 ms |
50908 KB |
Output is correct |
11 |
Correct |
34 ms |
50904 KB |
Output is correct |
12 |
Correct |
33 ms |
50400 KB |
Output is correct |
13 |
Correct |
36 ms |
50908 KB |
Output is correct |
14 |
Correct |
36 ms |
50764 KB |
Output is correct |
15 |
Correct |
37 ms |
50900 KB |
Output is correct |
16 |
Correct |
34 ms |
50904 KB |
Output is correct |
17 |
Correct |
39 ms |
50912 KB |
Output is correct |
18 |
Correct |
32 ms |
50388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
79028 KB |
Output is correct |
2 |
Correct |
347 ms |
81080 KB |
Output is correct |
3 |
Correct |
358 ms |
79288 KB |
Output is correct |
4 |
Correct |
238 ms |
77748 KB |
Output is correct |
5 |
Correct |
327 ms |
76384 KB |
Output is correct |
6 |
Correct |
118 ms |
67912 KB |
Output is correct |
7 |
Correct |
375 ms |
80564 KB |
Output is correct |
8 |
Correct |
332 ms |
79056 KB |
Output is correct |
9 |
Correct |
341 ms |
79296 KB |
Output is correct |
10 |
Correct |
354 ms |
76216 KB |
Output is correct |
11 |
Correct |
224 ms |
77748 KB |
Output is correct |
12 |
Correct |
100 ms |
67260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
79028 KB |
Output is correct |
2 |
Correct |
347 ms |
81080 KB |
Output is correct |
3 |
Correct |
358 ms |
79288 KB |
Output is correct |
4 |
Correct |
238 ms |
77748 KB |
Output is correct |
5 |
Correct |
327 ms |
76384 KB |
Output is correct |
6 |
Correct |
118 ms |
67912 KB |
Output is correct |
7 |
Correct |
375 ms |
80564 KB |
Output is correct |
8 |
Correct |
332 ms |
79056 KB |
Output is correct |
9 |
Correct |
341 ms |
79296 KB |
Output is correct |
10 |
Correct |
354 ms |
76216 KB |
Output is correct |
11 |
Correct |
224 ms |
77748 KB |
Output is correct |
12 |
Correct |
100 ms |
67260 KB |
Output is correct |
13 |
Correct |
457 ms |
80308 KB |
Output is correct |
14 |
Correct |
421 ms |
79800 KB |
Output is correct |
15 |
Correct |
352 ms |
79188 KB |
Output is correct |
16 |
Correct |
311 ms |
77500 KB |
Output is correct |
17 |
Correct |
373 ms |
76104 KB |
Output is correct |
18 |
Correct |
149 ms |
68160 KB |
Output is correct |
19 |
Correct |
411 ms |
80052 KB |
Output is correct |
20 |
Correct |
439 ms |
79544 KB |
Output is correct |
21 |
Correct |
416 ms |
80204 KB |
Output is correct |
22 |
Correct |
362 ms |
75188 KB |
Output is correct |
23 |
Correct |
223 ms |
78260 KB |
Output is correct |
24 |
Correct |
112 ms |
67004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
50152 KB |
Output is correct |
2 |
Correct |
30 ms |
50000 KB |
Output is correct |
3 |
Correct |
27 ms |
50012 KB |
Output is correct |
4 |
Correct |
27 ms |
50012 KB |
Output is correct |
5 |
Correct |
29 ms |
50012 KB |
Output is correct |
6 |
Correct |
37 ms |
50004 KB |
Output is correct |
7 |
Correct |
47 ms |
50904 KB |
Output is correct |
8 |
Correct |
36 ms |
50900 KB |
Output is correct |
9 |
Correct |
40 ms |
50904 KB |
Output is correct |
10 |
Correct |
41 ms |
50908 KB |
Output is correct |
11 |
Correct |
34 ms |
50904 KB |
Output is correct |
12 |
Correct |
33 ms |
50400 KB |
Output is correct |
13 |
Correct |
36 ms |
50908 KB |
Output is correct |
14 |
Correct |
36 ms |
50764 KB |
Output is correct |
15 |
Correct |
37 ms |
50900 KB |
Output is correct |
16 |
Correct |
34 ms |
50904 KB |
Output is correct |
17 |
Correct |
39 ms |
50912 KB |
Output is correct |
18 |
Correct |
32 ms |
50388 KB |
Output is correct |
19 |
Correct |
357 ms |
79028 KB |
Output is correct |
20 |
Correct |
347 ms |
81080 KB |
Output is correct |
21 |
Correct |
358 ms |
79288 KB |
Output is correct |
22 |
Correct |
238 ms |
77748 KB |
Output is correct |
23 |
Correct |
327 ms |
76384 KB |
Output is correct |
24 |
Correct |
118 ms |
67912 KB |
Output is correct |
25 |
Correct |
375 ms |
80564 KB |
Output is correct |
26 |
Correct |
332 ms |
79056 KB |
Output is correct |
27 |
Correct |
341 ms |
79296 KB |
Output is correct |
28 |
Correct |
354 ms |
76216 KB |
Output is correct |
29 |
Correct |
224 ms |
77748 KB |
Output is correct |
30 |
Correct |
100 ms |
67260 KB |
Output is correct |
31 |
Correct |
457 ms |
80308 KB |
Output is correct |
32 |
Correct |
421 ms |
79800 KB |
Output is correct |
33 |
Correct |
352 ms |
79188 KB |
Output is correct |
34 |
Correct |
311 ms |
77500 KB |
Output is correct |
35 |
Correct |
373 ms |
76104 KB |
Output is correct |
36 |
Correct |
149 ms |
68160 KB |
Output is correct |
37 |
Correct |
411 ms |
80052 KB |
Output is correct |
38 |
Correct |
439 ms |
79544 KB |
Output is correct |
39 |
Correct |
416 ms |
80204 KB |
Output is correct |
40 |
Correct |
362 ms |
75188 KB |
Output is correct |
41 |
Correct |
223 ms |
78260 KB |
Output is correct |
42 |
Correct |
112 ms |
67004 KB |
Output is correct |
43 |
Correct |
484 ms |
83676 KB |
Output is correct |
44 |
Correct |
543 ms |
84576 KB |
Output is correct |
45 |
Correct |
538 ms |
84372 KB |
Output is correct |
46 |
Correct |
334 ms |
85516 KB |
Output is correct |
47 |
Correct |
454 ms |
82396 KB |
Output is correct |
48 |
Correct |
143 ms |
65972 KB |
Output is correct |
49 |
Correct |
489 ms |
84160 KB |
Output is correct |
50 |
Correct |
451 ms |
84668 KB |
Output is correct |
51 |
Correct |
447 ms |
84792 KB |
Output is correct |
52 |
Correct |
486 ms |
82680 KB |
Output is correct |
53 |
Correct |
244 ms |
84880 KB |
Output is correct |