Submission #961591

# Submission time Handle Problem Language Result Execution time Memory
961591 2024-04-12T08:40:05 Z starchan None (JOI16_matryoshka) C++17
51 / 100
270 ms 42816 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 = 2e5+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());/*
	cout << "Printing RH values" << endl;
	for(auto [u, v]: RH)
		cout << u << " " << v << endl;*/
	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 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 ms 500 KB Output is correct
9 Correct 1 ms 500 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 ms 500 KB Output is correct
9 Correct 1 ms 500 KB Output is correct
10 Correct 1 ms 348 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 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 ms 500 KB Output is correct
9 Correct 1 ms 500 KB Output is correct
10 Correct 1 ms 348 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 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 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 2 ms 604 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 3 ms 860 KB Output is correct
34 Correct 3 ms 856 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 ms 500 KB Output is correct
9 Correct 1 ms 500 KB Output is correct
10 Correct 1 ms 348 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 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 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 2 ms 604 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 3 ms 860 KB Output is correct
34 Correct 3 ms 856 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 258 ms 22380 KB Output is correct
37 Correct 205 ms 23340 KB Output is correct
38 Correct 79 ms 9416 KB Output is correct
39 Correct 161 ms 16528 KB Output is correct
40 Correct 171 ms 17712 KB Output is correct
41 Correct 213 ms 20380 KB Output is correct
42 Correct 112 ms 15764 KB Output is correct
43 Correct 86 ms 15904 KB Output is correct
44 Runtime error 270 ms 42816 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -