답안 #880465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880465 2023-11-29T13:05:53 Z Youssif_Elkadi Osumnjičeni (COCI21_osumnjiceni) C++17
0 / 110
2 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, mod = 1e9 + 7, inf = 1e9 + 5;
int tree[N * 4], lazy[N * 4];
int n;
void prob(int l, int r, int node)
{
	tree[node] += lazy[node];
	if (l != r)
		lazy[node * 2] += lazy[node], lazy[node * 2 + 1] += lazy[node];
	lazy[node] = 0;
}
void update(int lq, int rq, int val, int l = 1, int r = n, int node = 1)
{
	prob(l, r, node);
	if (lq <= l && r <= rq)
	{
		lazy[node] += val;
		prob(l, r, node);
		return;
	}
	if (r < lq || l > rq)
		return;
	int mid = (l + r) / 2;
	update(lq, rq, val, l, mid, node * 2), update(lq, rq, val, mid + 1, r, node * 2 + 1);
	tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
int query(int lq, int rq, int l = 1, int r = n, int node = 1)
{
	prob(l, r, node);
	if (lq <= l && r <= rq)
		return tree[node];
	if (r < lq || l > rq)
		return 0;
	int mid = (l + r) / 2;
	return max(query(lq, rq, l, mid, node * 2), query(lq, rq, mid + 1, r, node * 2 + 1));
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cin >> n;
	vector<pair<int, int>> arr(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> arr[i].first >> arr[i].second;
	int q;
	cin >> q;
	while (q--)
	{
		int l, r;
		cin >> l >> r;
		int lst = l;
		int ans = 1;
		for (int i = l; i <= r; i++)
		{
			update(arr[i].first, arr[i].second, 1);
			if (query(1, n) > 1)
			{
				ans++;
				for (int k = lst; k < i; k++)
					update(arr[k].first, arr[k].second, -1);
				lst = i;
			}
		}
		for (int i = lst; i <= r; i++)
			update(arr[i].first, arr[i].second, -1);
		cout << ans << "\n";
	}
}
/*
3
1
3
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -