Submission #862684

# Submission time Handle Problem Language Result Execution time Memory
862684 2023-10-18T20:40:46 Z Cyber_Wolf Osumnjičeni (COCI21_osumnjiceni) C++17
30 / 110
1000 ms 95204 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()
{
	lg n;
	cin >> n;
	map<lg, lg> mp;
	lg id = 1;
	set<lg> o;
	for(int i = 1; i <= n; i++)
	{
		cin >> l[i] >> r[i];
		o.insert(l[i]);
		o.insert(r[i]);
	}
	for(auto it : o)
	{
		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 < 20; j++)
		{
			anc[i][j] = anc[anc[i][j-1]+1][j-1];
		}
	}
	// for(int i = 1; i <= n; i++)
	// {
		// for(int j = 0; j < 5; j++)
		// {
			// cout << anc[i][j] << ' ';
		// }
		// cout << '\n';
	// }
	lg q;
	cin >> q;
	while(q--)
	{
		lg a, b;
		cin >> a >> b;
		lg ans = 0;
		for(int i = 19; 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)
      |     ~~~^~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1033 ms 92516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5976 KB Output is correct
2 Correct 22 ms 8028 KB Output is correct
3 Correct 22 ms 8048 KB Output is correct
4 Correct 26 ms 10076 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5040 KB Output is correct
7 Correct 15 ms 4700 KB Output is correct
8 Correct 15 ms 4696 KB Output is correct
9 Correct 15 ms 4780 KB Output is correct
10 Correct 16 ms 4696 KB Output is correct
11 Correct 17 ms 8280 KB Output is correct
12 Correct 17 ms 6088 KB Output is correct
13 Correct 17 ms 8028 KB Output is correct
14 Correct 18 ms 8028 KB Output is correct
15 Correct 18 ms 8144 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 14 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5976 KB Output is correct
2 Correct 22 ms 8028 KB Output is correct
3 Correct 22 ms 8048 KB Output is correct
4 Correct 26 ms 10076 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5040 KB Output is correct
7 Correct 15 ms 4700 KB Output is correct
8 Correct 15 ms 4696 KB Output is correct
9 Correct 15 ms 4780 KB Output is correct
10 Correct 16 ms 4696 KB Output is correct
11 Correct 17 ms 8280 KB Output is correct
12 Correct 17 ms 6088 KB Output is correct
13 Correct 17 ms 8028 KB Output is correct
14 Correct 18 ms 8028 KB Output is correct
15 Correct 18 ms 8144 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 14 ms 4700 KB Output is correct
18 Correct 340 ms 10828 KB Output is correct
19 Correct 306 ms 10480 KB Output is correct
20 Correct 342 ms 13004 KB Output is correct
21 Correct 306 ms 10428 KB Output is correct
22 Correct 323 ms 8792 KB Output is correct
23 Correct 326 ms 7200 KB Output is correct
24 Correct 321 ms 7260 KB Output is correct
25 Correct 375 ms 7248 KB Output is correct
26 Correct 336 ms 7508 KB Output is correct
27 Correct 335 ms 7116 KB Output is correct
28 Correct 296 ms 10076 KB Output is correct
29 Correct 308 ms 8132 KB Output is correct
30 Correct 309 ms 12128 KB Output is correct
31 Correct 309 ms 8200 KB Output is correct
32 Correct 304 ms 10080 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 310 ms 6996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 95204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1033 ms 92516 KB Time limit exceeded
2 Halted 0 ms 0 KB -