Submission #961594

# Submission time Handle Problem Language Result Execution time Memory
961594 2024-04-12T08:41:17 Z starchan None (JOI16_matryoshka) C++17
100 / 100
284 ms 29400 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17

#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)

const int MX = 5e5+5;

int fen[MX];

void upd(int x, int val)
{
	for(; x < MX; x+=(x&-x))
		fen[x] = max(fen[x], val);
}

int query(int x)
{
	int ret = 0;
	for(; x; x-=(x&-x))
		ret = max(ret, fen[x]);
	return ret;
}

vector<int> G;
vector<int> H;
signed main()
{
	fast();
	int n, q;
	cin >> n >> q;
	vector<pair<in, int>> Q(q);
	vector<in> RH(n+1);
	RH[0] = {-INF, -1};
	for(int i = 1; i <= n; i++)
	{
		cin >> RH[i].f >> RH[i].s;
		RH[i].f = -RH[i].f;
		G.pb(RH[i].f);
	}
	for(int i = 0; i < q; i++)
	{
		Q[i].s = i;
		cin >> Q[i].f.f >> Q[i].f.s;
		Q[i].f.f = -Q[i].f.f;
		G.pb(Q[i].f.f);
	}
	sort(RH.begin(), RH.end());
	sort(G.begin(), G.end());
	H.pb(G[0]);
	for(auto x: G)
	{
		if(x != H.back())
			H.pb(x);
	}
	G.clear();
	for(auto &[u, v]: RH)
	{
		u = lower_bound(H.begin(), H.end(), u)-H.begin()+1;
		G.pb(v);
	}
	for(auto &[qq, i]: Q)
	{
		qq.f = lower_bound(H.begin(), H.end(), qq.f)-H.begin()+1;
		G.pb(qq.s);
	}
	H.clear();
	sort(G.begin(), G.end());
	H.pb(G[0]);
	for(auto x: G)
	{
		if(x != H.back())
			H.pb(x);
	}
	for(auto &[u, v]: RH)
		v = lower_bound(H.begin(), H.end(), v)-H.begin()+1;
	for(auto &[qq, i]: Q)
		qq.s = lower_bound(H.begin(), H.end(), qq.s)-H.begin()+1;
	sort(Q.begin(), Q.end());
	int r = 1;
	vector<int> ans(q, 0);
	for(int i = 0; i < q; i++)
	{
		int x = Q[i].s;
		while((r <= n) && (RH[r].f <= Q[i].f.f))
		{
			upd(RH[r].s, query(RH[r].s)+1);
			r++;
		}
		ans[x] = query(Q[i].f.s);
	}
	for(int i = 0; i < q; i++)
		cout << ans[i] << "\n";
	return 0;
}	
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 255 ms 17260 KB Output is correct
37 Correct 210 ms 19480 KB Output is correct
38 Correct 78 ms 7128 KB Output is correct
39 Correct 158 ms 13436 KB Output is correct
40 Correct 155 ms 14016 KB Output is correct
41 Correct 214 ms 16004 KB Output is correct
42 Correct 121 ms 14120 KB Output is correct
43 Correct 80 ms 14344 KB Output is correct
44 Correct 274 ms 20028 KB Output is correct
45 Correct 275 ms 27708 KB Output is correct
46 Correct 284 ms 29400 KB Output is correct
47 Correct 278 ms 27356 KB Output is correct
48 Correct 266 ms 27944 KB Output is correct
49 Correct 268 ms 27264 KB Output is correct
50 Correct 270 ms 27852 KB Output is correct