Submission #924735

# Submission time Handle Problem Language Result Execution time Memory
924735 2024-02-09T15:33:37 Z denniskim Examination (JOI19_examination) C++17
100 / 100
600 ms 36616 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

struct gujo
{
	ll X, Y, Z, typ, idx;
	
	bool operator < (const gujo &xx) const
	{
		if(Z == xx.Z)
			return typ < xx.typ;
		
		return Z > xx.Z;
	}
};

ll n, q;
ll all, bll, cll;
vector<gujo> vec;
ll ans[400010];
ll siz;
ll siz2;

struct fenwicktree
{
	ll bit[400010];
	
	void init(ll SIZ)
	{
		for(ll i = 0 ; i <= SIZ ; i++)
			bit[i] = 0;
	}
	
	void update(ll w, ll v)
	{
		for(ll i = w ; i <= siz2 ; i += (i & (-i)))
			bit[i] += v;
	}
	
	ll query(ll w)
	{
		ll ret = 0;
		
		for(ll i = w ; i > 0 ; i -= (i & (-i)))
			ret += bit[i];
		
		return ret;
	}
}BIT;

void f(ll L, ll R)
{
	if(L >= R)
		return;
	
	ll mid = (L + R) >> 1;
	vector<ll> zip;
	vector< pair<pll, pll> > vv;
	
	for(ll i = L ; i <= mid ; i++)
	{
		if(vec[i].typ == 1)
		{
			zip.push_back(vec[i].X);
			zip.push_back(vec[i].Y);
		}
	}
	
	for(ll i = mid + 1 ; i <= R ; i++)
	{
		if(vec[i].typ == 2)
		{
			zip.push_back(vec[i].X);
			zip.push_back(vec[i].Y);
		}
	}
	
	compress(zip);
	siz2 = (ll)zip.size();
	
	for(ll i = L ; i <= mid ; i++)
	{
		if(vec[i].typ == 2)
			continue;
		
		ll x = lower_bound(zip.begin(), zip.end(), vec[i].X) - zip.begin() + 1;
		ll y = lower_bound(zip.begin(), zip.end(), vec[i].Y) - zip.begin() + 1;
		
		vv.push_back({{x, -1}, {y, -1}});
	}
	
	for(ll i = mid + 1 ; i <= R ; i++)
	{
		if(vec[i].typ == 1)
			continue;
		
		ll x = lower_bound(zip.begin(), zip.end(), vec[i].X) - zip.begin() + 1;
		ll y = lower_bound(zip.begin(), zip.end(), vec[i].Y) - zip.begin() + 1;
		
		vv.push_back({{x, -2}, {y, vec[i].idx}});
	}
	
	sort(vv.begin(), vv.end());
	reverse(vv.begin(), vv.end());
	
	for(auto &i : vv)
	{
		if(i.fi.se == -2)
			ans[i.se.se] += BIT.query(siz2) - BIT.query(i.se.fi - 1);
		else
			BIT.update(i.se.fi, 1);
	}
	
	BIT.init(siz2);
	
	f(L, mid);
	f(mid + 1, R);
}

int main(void)
{
	fastio
	
	cin >> n >> q;
	
	for(ll i = 1 ; i <= n ; i++)
	{
		cin >> all >> bll;
		vec.push_back({all, bll, all + bll, 1, i});
	}
	
	for(ll i = 1 ; i <= q ; i++)
	{
		cin >> all >> bll >> cll;
		vec.push_back({all, bll, cll, 2, i});
	}
	
	sort(vec.begin(), vec.end());
	siz = (ll)vec.size();
	
	f(0, siz - 1);
	
	for(ll i = 1 ; i <= q ; i++)
		cout << ans[i] en;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 11 ms 3224 KB Output is correct
8 Correct 12 ms 3100 KB Output is correct
9 Correct 11 ms 3224 KB Output is correct
10 Correct 10 ms 3220 KB Output is correct
11 Correct 10 ms 3056 KB Output is correct
12 Correct 7 ms 2968 KB Output is correct
13 Correct 11 ms 3428 KB Output is correct
14 Correct 11 ms 3732 KB Output is correct
15 Correct 12 ms 3480 KB Output is correct
16 Correct 8 ms 3220 KB Output is correct
17 Correct 8 ms 3220 KB Output is correct
18 Correct 5 ms 3220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 33516 KB Output is correct
2 Correct 554 ms 34984 KB Output is correct
3 Correct 577 ms 35244 KB Output is correct
4 Correct 415 ms 35060 KB Output is correct
5 Correct 441 ms 33708 KB Output is correct
6 Correct 314 ms 30764 KB Output is correct
7 Correct 539 ms 34452 KB Output is correct
8 Correct 576 ms 34024 KB Output is correct
9 Correct 535 ms 35824 KB Output is correct
10 Correct 361 ms 33712 KB Output is correct
11 Correct 351 ms 32176 KB Output is correct
12 Correct 228 ms 31404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 33516 KB Output is correct
2 Correct 554 ms 34984 KB Output is correct
3 Correct 577 ms 35244 KB Output is correct
4 Correct 415 ms 35060 KB Output is correct
5 Correct 441 ms 33708 KB Output is correct
6 Correct 314 ms 30764 KB Output is correct
7 Correct 539 ms 34452 KB Output is correct
8 Correct 576 ms 34024 KB Output is correct
9 Correct 535 ms 35824 KB Output is correct
10 Correct 361 ms 33712 KB Output is correct
11 Correct 351 ms 32176 KB Output is correct
12 Correct 228 ms 31404 KB Output is correct
13 Correct 543 ms 27100 KB Output is correct
14 Correct 599 ms 32868 KB Output is correct
15 Correct 548 ms 36616 KB Output is correct
16 Correct 438 ms 26980 KB Output is correct
17 Correct 482 ms 27820 KB Output is correct
18 Correct 319 ms 29104 KB Output is correct
19 Correct 546 ms 27056 KB Output is correct
20 Correct 579 ms 30632 KB Output is correct
21 Correct 547 ms 28844 KB Output is correct
22 Correct 365 ms 32432 KB Output is correct
23 Correct 348 ms 32432 KB Output is correct
24 Correct 234 ms 30132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 11 ms 3224 KB Output is correct
8 Correct 12 ms 3100 KB Output is correct
9 Correct 11 ms 3224 KB Output is correct
10 Correct 10 ms 3220 KB Output is correct
11 Correct 10 ms 3056 KB Output is correct
12 Correct 7 ms 2968 KB Output is correct
13 Correct 11 ms 3428 KB Output is correct
14 Correct 11 ms 3732 KB Output is correct
15 Correct 12 ms 3480 KB Output is correct
16 Correct 8 ms 3220 KB Output is correct
17 Correct 8 ms 3220 KB Output is correct
18 Correct 5 ms 3220 KB Output is correct
19 Correct 555 ms 33516 KB Output is correct
20 Correct 554 ms 34984 KB Output is correct
21 Correct 577 ms 35244 KB Output is correct
22 Correct 415 ms 35060 KB Output is correct
23 Correct 441 ms 33708 KB Output is correct
24 Correct 314 ms 30764 KB Output is correct
25 Correct 539 ms 34452 KB Output is correct
26 Correct 576 ms 34024 KB Output is correct
27 Correct 535 ms 35824 KB Output is correct
28 Correct 361 ms 33712 KB Output is correct
29 Correct 351 ms 32176 KB Output is correct
30 Correct 228 ms 31404 KB Output is correct
31 Correct 543 ms 27100 KB Output is correct
32 Correct 599 ms 32868 KB Output is correct
33 Correct 548 ms 36616 KB Output is correct
34 Correct 438 ms 26980 KB Output is correct
35 Correct 482 ms 27820 KB Output is correct
36 Correct 319 ms 29104 KB Output is correct
37 Correct 546 ms 27056 KB Output is correct
38 Correct 579 ms 30632 KB Output is correct
39 Correct 547 ms 28844 KB Output is correct
40 Correct 365 ms 32432 KB Output is correct
41 Correct 348 ms 32432 KB Output is correct
42 Correct 234 ms 30132 KB Output is correct
43 Correct 552 ms 29360 KB Output is correct
44 Correct 556 ms 29156 KB Output is correct
45 Correct 600 ms 36040 KB Output is correct
46 Correct 432 ms 28048 KB Output is correct
47 Correct 474 ms 29404 KB Output is correct
48 Correct 305 ms 22476 KB Output is correct
49 Correct 577 ms 35976 KB Output is correct
50 Correct 542 ms 31560 KB Output is correct
51 Correct 585 ms 35760 KB Output is correct
52 Correct 411 ms 26152 KB Output is correct
53 Correct 351 ms 35272 KB Output is correct