Submission #1024082

# Submission time Handle Problem Language Result Execution time Memory
1024082 2024-07-15T11:35:45 Z vjudge1 Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
585 ms 31184 KB
// Time: 15-07-2024 16:33:04
// Problem: E - Osumnjičeni
// Contest: Virtual Judge - COCI 2021 Contest # 2
// URL: https://vjudge.net/contest/640690#problem/E
// Memory Limit: 512 MB
// Time Limit: 1000 ms

#include <bits/stdc++.h>

using namespace std;

bool valid(multiset<pair<int,int>> &se,pair<int,int> p)
{
	auto it=se.insert(p);
	if (it!=se.begin())
	{
		it--;
		if ((*it).second>=p.first)
		{
			se.erase(++it);
			return 0;
		}
		it++;
	}
	it++;
	if (it!=se.end())
	{
		if ((*it).first<=p.second)
		{
			se.erase(--it);
			return 0;
		}
	}
	return 1;
}

int main()
{
	int n;
	cin>>n;
	vector<pair<int,int>> vec;
	for (int i=0;i<n;i++)
	{
		int l,r;
		cin>>l>>r;
		vec.push_back({l,r});
	}
	multiset<pair<int,int>> se;
	int i=0,j=0;
	int rc[n+1][18];
	while (i<n)
	{
		if (j<n)
		{
			while (j<n && valid(se,vec[j]))
				j++;
		}
		rc[i][0]=j;
		se.erase(se.find(vec[i]));
		i++;
	}
	for (int i=0;i<18;i++)
		rc[n][i]=n;
	for (int p=1;p<18;p++)
		for (int i=0;i<n;i++)
			rc[i][p]=rc[rc[i][p-1]][p-1];
	int q;
	cin>>q;
	while (q--)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		int ans=1;
		for (int p=17;p>=0;p--)
			if (rc[a][p]<=b)
				ans+=(1<<p),a=rc[a][p];
		cout<<ans<<'\n';
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 118 ms 15276 KB Output is correct
2 Correct 118 ms 18836 KB Output is correct
3 Correct 123 ms 18872 KB Output is correct
4 Correct 131 ms 19128 KB Output is correct
5 Correct 125 ms 19800 KB Output is correct
6 Correct 110 ms 18112 KB Output is correct
7 Correct 117 ms 18364 KB Output is correct
8 Correct 118 ms 18416 KB Output is correct
9 Correct 127 ms 18872 KB Output is correct
10 Correct 116 ms 18368 KB Output is correct
11 Correct 194 ms 28092 KB Output is correct
12 Correct 193 ms 26304 KB Output is correct
13 Correct 203 ms 26112 KB Output is correct
14 Correct 191 ms 23996 KB Output is correct
15 Correct 185 ms 22336 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 130 ms 19308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 856 KB Output is correct
2 Correct 14 ms 1008 KB Output is correct
3 Correct 11 ms 860 KB Output is correct
4 Correct 11 ms 1024 KB Output is correct
5 Correct 10 ms 992 KB Output is correct
6 Correct 15 ms 1220 KB Output is correct
7 Correct 11 ms 832 KB Output is correct
8 Correct 13 ms 856 KB Output is correct
9 Correct 11 ms 856 KB Output is correct
10 Correct 10 ms 860 KB Output is correct
11 Correct 10 ms 956 KB Output is correct
12 Correct 10 ms 1128 KB Output is correct
13 Correct 10 ms 1008 KB Output is correct
14 Correct 10 ms 1036 KB Output is correct
15 Correct 10 ms 1012 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 10 ms 1008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 856 KB Output is correct
2 Correct 14 ms 1008 KB Output is correct
3 Correct 11 ms 860 KB Output is correct
4 Correct 11 ms 1024 KB Output is correct
5 Correct 10 ms 992 KB Output is correct
6 Correct 15 ms 1220 KB Output is correct
7 Correct 11 ms 832 KB Output is correct
8 Correct 13 ms 856 KB Output is correct
9 Correct 11 ms 856 KB Output is correct
10 Correct 10 ms 860 KB Output is correct
11 Correct 10 ms 956 KB Output is correct
12 Correct 10 ms 1128 KB Output is correct
13 Correct 10 ms 1008 KB Output is correct
14 Correct 10 ms 1036 KB Output is correct
15 Correct 10 ms 1012 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 10 ms 1008 KB Output is correct
18 Correct 347 ms 3668 KB Output is correct
19 Correct 263 ms 3408 KB Output is correct
20 Correct 300 ms 3548 KB Output is correct
21 Correct 265 ms 3408 KB Output is correct
22 Correct 289 ms 3408 KB Output is correct
23 Correct 290 ms 3352 KB Output is correct
24 Correct 291 ms 3512 KB Output is correct
25 Correct 297 ms 3408 KB Output is correct
26 Correct 285 ms 3480 KB Output is correct
27 Correct 279 ms 3248 KB Output is correct
28 Correct 276 ms 3156 KB Output is correct
29 Correct 279 ms 3236 KB Output is correct
30 Correct 290 ms 3152 KB Output is correct
31 Correct 273 ms 2900 KB Output is correct
32 Correct 266 ms 2896 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 271 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 16064 KB Output is correct
2 Correct 128 ms 19616 KB Output is correct
3 Correct 119 ms 18148 KB Output is correct
4 Correct 117 ms 18108 KB Output is correct
5 Correct 120 ms 18628 KB Output is correct
6 Correct 117 ms 18364 KB Output is correct
7 Correct 132 ms 18108 KB Output is correct
8 Correct 125 ms 18328 KB Output is correct
9 Correct 153 ms 18200 KB Output is correct
10 Correct 134 ms 19468 KB Output is correct
11 Correct 285 ms 26044 KB Output is correct
12 Correct 297 ms 28664 KB Output is correct
13 Correct 220 ms 25920 KB Output is correct
14 Correct 199 ms 22400 KB Output is correct
15 Correct 197 ms 24400 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 129 ms 18620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 15276 KB Output is correct
2 Correct 118 ms 18836 KB Output is correct
3 Correct 123 ms 18872 KB Output is correct
4 Correct 131 ms 19128 KB Output is correct
5 Correct 125 ms 19800 KB Output is correct
6 Correct 110 ms 18112 KB Output is correct
7 Correct 117 ms 18364 KB Output is correct
8 Correct 118 ms 18416 KB Output is correct
9 Correct 127 ms 18872 KB Output is correct
10 Correct 116 ms 18368 KB Output is correct
11 Correct 194 ms 28092 KB Output is correct
12 Correct 193 ms 26304 KB Output is correct
13 Correct 203 ms 26112 KB Output is correct
14 Correct 191 ms 23996 KB Output is correct
15 Correct 185 ms 22336 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 130 ms 19308 KB Output is correct
18 Correct 10 ms 856 KB Output is correct
19 Correct 14 ms 1008 KB Output is correct
20 Correct 11 ms 860 KB Output is correct
21 Correct 11 ms 1024 KB Output is correct
22 Correct 10 ms 992 KB Output is correct
23 Correct 15 ms 1220 KB Output is correct
24 Correct 11 ms 832 KB Output is correct
25 Correct 13 ms 856 KB Output is correct
26 Correct 11 ms 856 KB Output is correct
27 Correct 10 ms 860 KB Output is correct
28 Correct 10 ms 956 KB Output is correct
29 Correct 10 ms 1128 KB Output is correct
30 Correct 10 ms 1008 KB Output is correct
31 Correct 10 ms 1036 KB Output is correct
32 Correct 10 ms 1012 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 10 ms 1008 KB Output is correct
35 Correct 347 ms 3668 KB Output is correct
36 Correct 263 ms 3408 KB Output is correct
37 Correct 300 ms 3548 KB Output is correct
38 Correct 265 ms 3408 KB Output is correct
39 Correct 289 ms 3408 KB Output is correct
40 Correct 290 ms 3352 KB Output is correct
41 Correct 291 ms 3512 KB Output is correct
42 Correct 297 ms 3408 KB Output is correct
43 Correct 285 ms 3480 KB Output is correct
44 Correct 279 ms 3248 KB Output is correct
45 Correct 276 ms 3156 KB Output is correct
46 Correct 279 ms 3236 KB Output is correct
47 Correct 290 ms 3152 KB Output is correct
48 Correct 273 ms 2900 KB Output is correct
49 Correct 266 ms 2896 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 271 ms 3176 KB Output is correct
52 Correct 149 ms 16064 KB Output is correct
53 Correct 128 ms 19616 KB Output is correct
54 Correct 119 ms 18148 KB Output is correct
55 Correct 117 ms 18108 KB Output is correct
56 Correct 120 ms 18628 KB Output is correct
57 Correct 117 ms 18364 KB Output is correct
58 Correct 132 ms 18108 KB Output is correct
59 Correct 125 ms 18328 KB Output is correct
60 Correct 153 ms 18200 KB Output is correct
61 Correct 134 ms 19468 KB Output is correct
62 Correct 285 ms 26044 KB Output is correct
63 Correct 297 ms 28664 KB Output is correct
64 Correct 220 ms 25920 KB Output is correct
65 Correct 199 ms 22400 KB Output is correct
66 Correct 197 ms 24400 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 129 ms 18620 KB Output is correct
69 Correct 549 ms 22016 KB Output is correct
70 Correct 455 ms 23024 KB Output is correct
71 Correct 450 ms 21436 KB Output is correct
72 Correct 477 ms 22468 KB Output is correct
73 Correct 468 ms 22204 KB Output is correct
74 Correct 474 ms 23532 KB Output is correct
75 Correct 469 ms 21880 KB Output is correct
76 Correct 455 ms 23468 KB Output is correct
77 Correct 585 ms 21616 KB Output is correct
78 Correct 467 ms 22208 KB Output is correct
79 Correct 571 ms 31184 KB Output is correct
80 Correct 537 ms 28948 KB Output is correct
81 Correct 552 ms 28968 KB Output is correct
82 Correct 581 ms 25476 KB Output is correct
83 Correct 458 ms 24580 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 442 ms 21836 KB Output is correct