답안 #862685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862685 2023-10-18T20:45:28 Z Cyber_Wolf Osumnjičeni (COCI21_osumnjiceni) C++17
40 / 110
1000 ms 99232 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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;
	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 < 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:31:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   31 |  if(lq <= lr & hr <= hq)
      |     ~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 989 ms 92500 KB Output is correct
2 Correct 935 ms 96000 KB Output is correct
3 Correct 904 ms 95520 KB Output is correct
4 Correct 912 ms 96228 KB Output is correct
5 Correct 954 ms 99232 KB Output is correct
6 Correct 129 ms 36176 KB Output is correct
7 Correct 143 ms 38588 KB Output is correct
8 Correct 139 ms 38464 KB Output is correct
9 Correct 144 ms 38472 KB Output is correct
10 Correct 143 ms 38224 KB Output is correct
11 Correct 626 ms 96932 KB Output is correct
12 Correct 560 ms 93252 KB Output is correct
13 Correct 552 ms 93284 KB Output is correct
14 Correct 601 ms 97072 KB Output is correct
15 Correct 630 ms 95312 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 140 ms 38824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5976 KB Output is correct
2 Correct 13 ms 8028 KB Output is correct
3 Correct 12 ms 9820 KB Output is correct
4 Correct 13 ms 10020 KB Output is correct
5 Correct 12 ms 8028 KB Output is correct
6 Correct 5 ms 4440 KB Output is correct
7 Correct 6 ms 4700 KB Output is correct
8 Correct 5 ms 4672 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 5 ms 4668 KB Output is correct
11 Correct 9 ms 8028 KB Output is correct
12 Correct 8 ms 5980 KB Output is correct
13 Correct 8 ms 8028 KB Output is correct
14 Correct 9 ms 7772 KB Output is correct
15 Correct 10 ms 8028 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5976 KB Output is correct
2 Correct 13 ms 8028 KB Output is correct
3 Correct 12 ms 9820 KB Output is correct
4 Correct 13 ms 10020 KB Output is correct
5 Correct 12 ms 8028 KB Output is correct
6 Correct 5 ms 4440 KB Output is correct
7 Correct 6 ms 4700 KB Output is correct
8 Correct 5 ms 4672 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 5 ms 4668 KB Output is correct
11 Correct 9 ms 8028 KB Output is correct
12 Correct 8 ms 5980 KB Output is correct
13 Correct 8 ms 8028 KB Output is correct
14 Correct 9 ms 7772 KB Output is correct
15 Correct 10 ms 8028 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 69 ms 8656 KB Output is correct
19 Correct 65 ms 8524 KB Output is correct
20 Correct 71 ms 10828 KB Output is correct
21 Correct 71 ms 8672 KB Output is correct
22 Correct 69 ms 6776 KB Output is correct
23 Correct 58 ms 5456 KB Output is correct
24 Correct 60 ms 5412 KB Output is correct
25 Correct 66 ms 5248 KB Output is correct
26 Correct 57 ms 5296 KB Output is correct
27 Correct 54 ms 5188 KB Output is correct
28 Correct 46 ms 8304 KB Output is correct
29 Correct 57 ms 6292 KB Output is correct
30 Correct 54 ms 10324 KB Output is correct
31 Correct 48 ms 6344 KB Output is correct
32 Correct 59 ms 8352 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 48 ms 5620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1024 ms 95244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 989 ms 92500 KB Output is correct
2 Correct 935 ms 96000 KB Output is correct
3 Correct 904 ms 95520 KB Output is correct
4 Correct 912 ms 96228 KB Output is correct
5 Correct 954 ms 99232 KB Output is correct
6 Correct 129 ms 36176 KB Output is correct
7 Correct 143 ms 38588 KB Output is correct
8 Correct 139 ms 38464 KB Output is correct
9 Correct 144 ms 38472 KB Output is correct
10 Correct 143 ms 38224 KB Output is correct
11 Correct 626 ms 96932 KB Output is correct
12 Correct 560 ms 93252 KB Output is correct
13 Correct 552 ms 93284 KB Output is correct
14 Correct 601 ms 97072 KB Output is correct
15 Correct 630 ms 95312 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 140 ms 38824 KB Output is correct
18 Correct 13 ms 5976 KB Output is correct
19 Correct 13 ms 8028 KB Output is correct
20 Correct 12 ms 9820 KB Output is correct
21 Correct 13 ms 10020 KB Output is correct
22 Correct 12 ms 8028 KB Output is correct
23 Correct 5 ms 4440 KB Output is correct
24 Correct 6 ms 4700 KB Output is correct
25 Correct 5 ms 4672 KB Output is correct
26 Correct 5 ms 4444 KB Output is correct
27 Correct 5 ms 4668 KB Output is correct
28 Correct 9 ms 8028 KB Output is correct
29 Correct 8 ms 5980 KB Output is correct
30 Correct 8 ms 8028 KB Output is correct
31 Correct 9 ms 7772 KB Output is correct
32 Correct 10 ms 8028 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 5 ms 4444 KB Output is correct
35 Correct 69 ms 8656 KB Output is correct
36 Correct 65 ms 8524 KB Output is correct
37 Correct 71 ms 10828 KB Output is correct
38 Correct 71 ms 8672 KB Output is correct
39 Correct 69 ms 6776 KB Output is correct
40 Correct 58 ms 5456 KB Output is correct
41 Correct 60 ms 5412 KB Output is correct
42 Correct 66 ms 5248 KB Output is correct
43 Correct 57 ms 5296 KB Output is correct
44 Correct 54 ms 5188 KB Output is correct
45 Correct 46 ms 8304 KB Output is correct
46 Correct 57 ms 6292 KB Output is correct
47 Correct 54 ms 10324 KB Output is correct
48 Correct 48 ms 6344 KB Output is correct
49 Correct 59 ms 8352 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 48 ms 5620 KB Output is correct
52 Execution timed out 1024 ms 95244 KB Time limit exceeded
53 Halted 0 ms 0 KB -