Submission #862687

# Submission time Handle Problem Language Result Execution time Memory
862687 2023-10-18T20:53:15 Z Cyber_Wolf Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
693 ms 76924 KB
#include <bits/stdc++.h>

using namespace std;

#define lg long long 
#define mid (lr+hr)/2

const lg N = 2e5+5;

lg l[N], r[N], anc[N][20], n, seg[(N << 3)][2];

void doLazy(lg node, lg lr, lg hr)
{
	if(!seg[node][1])	return;
	seg[node][0] += seg[node][1]*(hr-lr+1);
	if(lr != hr)
	{
		for(int ch = node*2; ch <= node*2+1; ch++)
		{
			seg[ch][1] += seg[node][1];
		}
	}
	seg[node][1] = 0;
}

void upd(lg node, lg lr, lg hr, lg lq, lg hq, lg val)
{
	doLazy(node, lr, hr);
	if(lr > hq || lq > hr)	return;
	if(lq <= lr & hr <= hq)
	{
		seg[node][1] += val;
		doLazy(node, lr, hr);
		return;
	}
	upd(node << 1, lr, mid, lq, hq, val);
	upd(node << 1 | 1, mid+1, hr, lq, hq, val);
	seg[node][0] = seg[node << 1][0]+seg[node << 1 | 1][0];
	return;
}

lg get(lg node, lg lr, lg hr, lg lq, lg hq)
{
	doLazy(node, lr, hr);
	if(lr > hq || lq > hr)	return 0;
	if(lq <= lr && hr <= hq)	return seg[node][0];
	return (get(node << 1, lr, mid, lq, hq)+get(node << 1 | 1, mid+1, hr, lq, hq));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	lg n;
	cin >> n;
	unordered_map<lg, lg> mp;
	lg id = 1;
	vector<lg> o;
	for(int i = 1; i <= n; i++)
	{
		cin >> l[i] >> r[i];
		o.push_back(l[i]);
		o.push_back(r[i]);
	}
	sort(o.begin(), o.end());
	for(int i = 0; i < o.size(); i++)
	{
		int it = o[i];
		if(i && it == o[i-1])	continue;
		mp[it] = id++;
	}
	for(int i = 1; i <= n; i++)
	{
		l[i] = mp[l[i]];
		r[i] = mp[r[i]];
	}
	lg en = 1;
	for(int i = 1; i <= n; i++)
	{
		while(en <= n)
		{
			if(get(1, 1, 4e5, l[en], r[en]))
			{
				break;
			}
			upd(1, 1, 4e5, l[en], r[en], 1);
			en++;
		}
		anc[i][0] = en-1;
		upd(1, 1, 4e5, l[i], r[i], -1);
	}
	for(int i = n; i >= 1; i--)
	{
		for(int j = 1; j < 19; j++)
		{
			anc[i][j] = anc[anc[i][j-1]+1][j-1];
		}
	}
	lg q;
	cin >> q;
	while(q--)
	{
		lg a, b;
		cin >> a >> b;
		lg ans = 0;
		for(int i = 18; i >= 0 && a <= b; i--)
		{
			if(anc[a][i] <= b && anc[a][i])
			{
				ans += (1ll << i);
				a = anc[a][i]+1;
			}
		}
		if(a <= b)	ans++;
		cout << ans << '\n';
	}
} 

Compilation message

Main.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:30:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   30 |  if(lq <= lr & hr <= hq)
      |     ~~~^~~~~
Main.cpp: In function 'int main()':
Main.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i = 0; i < o.size(); i++)
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 549 ms 73428 KB Output is correct
2 Correct 534 ms 72444 KB Output is correct
3 Correct 511 ms 72956 KB Output is correct
4 Correct 539 ms 73516 KB Output is correct
5 Correct 575 ms 75368 KB Output is correct
6 Correct 167 ms 37992 KB Output is correct
7 Correct 193 ms 39864 KB Output is correct
8 Correct 184 ms 39996 KB Output is correct
9 Correct 185 ms 40412 KB Output is correct
10 Correct 179 ms 41136 KB Output is correct
11 Correct 341 ms 74500 KB Output is correct
12 Correct 325 ms 72768 KB Output is correct
13 Correct 386 ms 72712 KB Output is correct
14 Correct 368 ms 73984 KB Output is correct
15 Correct 356 ms 73012 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 176 ms 40060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5672 KB Output is correct
2 Correct 11 ms 7516 KB Output is correct
3 Correct 11 ms 7508 KB Output is correct
4 Correct 12 ms 9560 KB Output is correct
5 Correct 11 ms 7652 KB Output is correct
6 Correct 6 ms 5028 KB Output is correct
7 Correct 7 ms 5020 KB Output is correct
8 Correct 9 ms 5184 KB Output is correct
9 Correct 7 ms 5012 KB Output is correct
10 Correct 7 ms 4952 KB Output is correct
11 Correct 8 ms 7516 KB Output is correct
12 Correct 7 ms 5612 KB Output is correct
13 Correct 7 ms 7512 KB Output is correct
14 Correct 8 ms 7516 KB Output is correct
15 Correct 8 ms 7644 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 6 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5672 KB Output is correct
2 Correct 11 ms 7516 KB Output is correct
3 Correct 11 ms 7508 KB Output is correct
4 Correct 12 ms 9560 KB Output is correct
5 Correct 11 ms 7652 KB Output is correct
6 Correct 6 ms 5028 KB Output is correct
7 Correct 7 ms 5020 KB Output is correct
8 Correct 9 ms 5184 KB Output is correct
9 Correct 7 ms 5012 KB Output is correct
10 Correct 7 ms 4952 KB Output is correct
11 Correct 8 ms 7516 KB Output is correct
12 Correct 7 ms 5612 KB Output is correct
13 Correct 7 ms 7512 KB Output is correct
14 Correct 8 ms 7516 KB Output is correct
15 Correct 8 ms 7644 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 6 ms 4956 KB Output is correct
18 Correct 66 ms 9552 KB Output is correct
19 Correct 61 ms 9200 KB Output is correct
20 Correct 67 ms 11600 KB Output is correct
21 Correct 60 ms 9552 KB Output is correct
22 Correct 77 ms 7512 KB Output is correct
23 Correct 58 ms 6468 KB Output is correct
24 Correct 59 ms 6996 KB Output is correct
25 Correct 63 ms 6812 KB Output is correct
26 Correct 56 ms 6696 KB Output is correct
27 Correct 56 ms 6732 KB Output is correct
28 Correct 41 ms 8860 KB Output is correct
29 Correct 45 ms 6964 KB Output is correct
30 Correct 43 ms 10832 KB Output is correct
31 Correct 44 ms 6996 KB Output is correct
32 Correct 44 ms 9280 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 46 ms 6668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 75348 KB Output is correct
2 Correct 539 ms 74344 KB Output is correct
3 Correct 502 ms 71912 KB Output is correct
4 Correct 530 ms 69788 KB Output is correct
5 Correct 531 ms 72956 KB Output is correct
6 Correct 169 ms 39872 KB Output is correct
7 Correct 186 ms 37824 KB Output is correct
8 Correct 175 ms 40512 KB Output is correct
9 Correct 175 ms 38664 KB Output is correct
10 Correct 198 ms 40472 KB Output is correct
11 Correct 312 ms 69376 KB Output is correct
12 Correct 350 ms 74744 KB Output is correct
13 Correct 292 ms 69888 KB Output is correct
14 Correct 346 ms 73216 KB Output is correct
15 Correct 382 ms 74208 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 168 ms 40020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 73428 KB Output is correct
2 Correct 534 ms 72444 KB Output is correct
3 Correct 511 ms 72956 KB Output is correct
4 Correct 539 ms 73516 KB Output is correct
5 Correct 575 ms 75368 KB Output is correct
6 Correct 167 ms 37992 KB Output is correct
7 Correct 193 ms 39864 KB Output is correct
8 Correct 184 ms 39996 KB Output is correct
9 Correct 185 ms 40412 KB Output is correct
10 Correct 179 ms 41136 KB Output is correct
11 Correct 341 ms 74500 KB Output is correct
12 Correct 325 ms 72768 KB Output is correct
13 Correct 386 ms 72712 KB Output is correct
14 Correct 368 ms 73984 KB Output is correct
15 Correct 356 ms 73012 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 176 ms 40060 KB Output is correct
18 Correct 14 ms 5672 KB Output is correct
19 Correct 11 ms 7516 KB Output is correct
20 Correct 11 ms 7508 KB Output is correct
21 Correct 12 ms 9560 KB Output is correct
22 Correct 11 ms 7652 KB Output is correct
23 Correct 6 ms 5028 KB Output is correct
24 Correct 7 ms 5020 KB Output is correct
25 Correct 9 ms 5184 KB Output is correct
26 Correct 7 ms 5012 KB Output is correct
27 Correct 7 ms 4952 KB Output is correct
28 Correct 8 ms 7516 KB Output is correct
29 Correct 7 ms 5612 KB Output is correct
30 Correct 7 ms 7512 KB Output is correct
31 Correct 8 ms 7516 KB Output is correct
32 Correct 8 ms 7644 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 6 ms 4956 KB Output is correct
35 Correct 66 ms 9552 KB Output is correct
36 Correct 61 ms 9200 KB Output is correct
37 Correct 67 ms 11600 KB Output is correct
38 Correct 60 ms 9552 KB Output is correct
39 Correct 77 ms 7512 KB Output is correct
40 Correct 58 ms 6468 KB Output is correct
41 Correct 59 ms 6996 KB Output is correct
42 Correct 63 ms 6812 KB Output is correct
43 Correct 56 ms 6696 KB Output is correct
44 Correct 56 ms 6732 KB Output is correct
45 Correct 41 ms 8860 KB Output is correct
46 Correct 45 ms 6964 KB Output is correct
47 Correct 43 ms 10832 KB Output is correct
48 Correct 44 ms 6996 KB Output is correct
49 Correct 44 ms 9280 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 46 ms 6668 KB Output is correct
52 Correct 549 ms 75348 KB Output is correct
53 Correct 539 ms 74344 KB Output is correct
54 Correct 502 ms 71912 KB Output is correct
55 Correct 530 ms 69788 KB Output is correct
56 Correct 531 ms 72956 KB Output is correct
57 Correct 169 ms 39872 KB Output is correct
58 Correct 186 ms 37824 KB Output is correct
59 Correct 175 ms 40512 KB Output is correct
60 Correct 175 ms 38664 KB Output is correct
61 Correct 198 ms 40472 KB Output is correct
62 Correct 312 ms 69376 KB Output is correct
63 Correct 350 ms 74744 KB Output is correct
64 Correct 292 ms 69888 KB Output is correct
65 Correct 346 ms 73216 KB Output is correct
66 Correct 382 ms 74208 KB Output is correct
67 Correct 1 ms 4440 KB Output is correct
68 Correct 168 ms 40020 KB Output is correct
69 Correct 637 ms 75952 KB Output is correct
70 Correct 693 ms 76924 KB Output is correct
71 Correct 616 ms 72768 KB Output is correct
72 Correct 682 ms 76572 KB Output is correct
73 Correct 638 ms 75044 KB Output is correct
74 Correct 339 ms 42864 KB Output is correct
75 Correct 305 ms 43124 KB Output is correct
76 Correct 315 ms 42812 KB Output is correct
77 Correct 283 ms 43028 KB Output is correct
78 Correct 268 ms 43080 KB Output is correct
79 Correct 393 ms 76300 KB Output is correct
80 Correct 377 ms 73356 KB Output is correct
81 Correct 362 ms 73064 KB Output is correct
82 Correct 413 ms 75888 KB Output is correct
83 Correct 395 ms 74076 KB Output is correct
84 Correct 1 ms 4456 KB Output is correct
85 Correct 217 ms 42300 KB Output is correct