2019-2020 ICPC, Asia Jakarta Regional Contest G. Performance Review(线段树)

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Randall is a software engineer at a company with NN employees. Every year, the company re-evaluates its employees. At the end of every year, the company replaces its several worst-performing employees and replaces with the same number of new employees, so that the company keeps having NN employees. Each person has a constant performance and can be represented by an integer (higher integer means better performance), and no two people have the same performance.

The performance of the initial employees are represented by an array of integers A=[A1,A2,…,AN]A=[A1,A2,…,AN] where AiAi is the performance of the ithith employee. Randall is employee 11, so his performance is A1A1. We will consider the first MM years. At the end of the ithith year, the company replaces its RiRi worst-performing employees and replaces with RiRi new employees. The performance of these new employees are represented by an array of integers Bi=[(Bi)1,(Bi)2,…,(Bi)Ri]Bi=[(Bi)1,(Bi)2,…,(Bi)Ri] where (Bi)j(Bi)j is the performance of the jthjth new employee.

He will consider QQ scenarios. On the ithith scenario, he will change the value of (BXi)Yi(BXi)Yi to ZiZi. For each scenario, Randall is wondering whether he will still be in the company after MM years. Note that the changes in each scenario are kept for the subsequent scenarios.

Input

Input begins with a line containing three integers: NN MM QQ (2≤N≤1000002≤N≤100000; 1≤M,Q≤1000001≤M,Q≤100000) representing the number of employees, the number of years to be considered, and the number of scenarios, respectively. The next line contains NN integers: AiAi (0≤Ai≤1090≤Ai≤109) representing the performance of the initial employees. The next MM lines each contains several integers: RiRi (Bi)1(Bi)1, (Bi)2(Bi)2, ⋯⋯, (Bi)Ri(Bi)Ri (1≤Ri<N1≤Ri<N; 0≤(Bi)j≤1090≤(Bi)j≤109) representing the number of employees replaced and the performance of the new employees, respectively. It is guaranteed that the sum of RiRi does not exceed 106106. The next QQ lines each contains three integers: XiXi YiYi ZiZi (1≤Xi≤M1≤Xi≤M; 1≤Yi≤R(Xi)1≤Yi≤R(Xi); 0≤Zi≤1090≤Zi≤109) representing a scenario. It is guaranteed that all integers in all AiAi, (Bi)j(Bi)j, and ZiZi (combined together) are distinct.

Output

For each scenario in the same order as input, output in a line an integer 00 if Randall will not be in the company after MM years, or 11 if Randall will still be in the company after MM years.

Example

input

Copy

5 3 3
50 40 30 20 10
4 1 2 3 100
1 4
2 6 7
1 3 300
2 1 400
2 1 5

output

Copy

1
0
1

Note

Explanation for the sample input/output #1

Randall performance is represented by 5050. For the first scenario, the value of (B1)3(B1)3 is updated to 300300, causes the following:

  • Initially, the performance of the employees is [50,40,30,20,10][50,40,30,20,10].
  • At the end of the first year, 44 worst-performing employees are replaced by employees with performance [300,100,2,1][300,100,2,1]. Therefore, the performance of the employees is [300,100,50,2,1][300,100,50,2,1].
  • At the end of the second year, the performance of the employees is [300,100,50,4,2][300,100,50,4,2].
  • At the end of the third year, the performance of the employees is [300,100,50,7,6][300,100,50,7,6].

Therefore, Randall will still be in the company after 33 years.

For the second scenario, the value of (B2)1(B2)1 is updated to 400400, causes the following:

  • Initially, the performance of the employees is [50,40,30,20,10][50,40,30,20,10].
  • At the end of the first year, the performance of the employees is [300,100,50,2,1][300,100,50,2,1]. Recall that the change in the first scenario is kept for this scenario as well.
  • At the end of the second year, the performance of the employees is [400,300,100,50,2][400,300,100,50,2].
  • At the end of the third year, the performance of the employees is [400,300,100,7,6][400,300,100,7,6].

Therefore, Randall will not be in the company after 33 years.

题意:

有一个公司有n个员工, 每个员工有n个能力值Ai, Randall的能力值为A1, 现在有m轮淘汰,

每次会淘汰能力值最小的Ri个,用m轮每轮的Ri替换掉被淘汰的Ri,接着会有Q轮预测, 每

次会修改第x轮的第y个元素为z,而且这Q轮修改不是独立的, 问你每轮修改后最终Randall

能否留下来。

思路:

每一轮都有一个Randall的排名, 如果≤0就代表要被淘汰了。

我们先求出Randall的初始排名, 再用数组a记录没有修改时

每轮开始淘汰后Randall的排名变化(还未修改),得到a数组后就可以建一颗线段树了。

设Randall的值为K,对于Q次修改, 设原始的值为G,当前修改的值为Z

若Z < K,K < G, 意味着Randall的排名可以++

 若Z > K,K > G, 意味着Randall的排名需要--

修改后, 线段树每个节点取个min, 检测有没有≤0的节点即可。

因为修改是在当前这轮淘汰操作之前执行, 所以每次修改会更新下一轮的ai

update(1, 1, m, x + 1, m, val); // 修改区间为[x + 1, m]

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define hash_ 1000000009
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
ll fpow(ll a, int b, int mod) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res % mod; }
const int mod = 1e9 + 7;
const int N = 2e5 + 100;
int c[N * 4];
int lzy[N * 4];
int a[N];
#define ls ((x) << 1)
#define rs ((x) << 1 | 1)
#define mid ((L) + (R) >> 1)
void push_up(int x)
{
	c[x] = min(c[ls], c[rs]);
}
void push_down(int x)
{
	if (lzy[x])
	{
		c[ls] += lzy[x], c[rs] += lzy[x];
		lzy[ls] += lzy[x], lzy[rs] += lzy[x];
		lzy[x] = 0;
	}
}
void build(int x, int L, int R)
{
	if (L == R)
	{
		c[x] = a[L];
		return;
	}
	build(ls, L, mid);
	build(rs, mid + 1, R);
	push_up(x);
}
void update(int x, int L, int R, int ql, int qr, int val)
{
	if (ql <= L && qr >= R)
	{
		c[x] += val;
		lzy[x] += val;
		return;
	}
	push_down(x);
	if (ql <= mid)
		update(ls, L, mid, ql, qr, val);
	if (qr > mid)
		update(rs, mid + 1, R, ql, qr, val);
	push_up(x);
}
#undef ls
#undef rs
#undef mid
vector<int>G[N];
int main()
{
#ifdef LOCAL 
	freopen("D:/input.txt", "r", stdin);
#endif
	int n, m, q, k;
	int rak = 1;
	cin >> n >> m >> q;
	cin >> k;
	for (int i = 2; i <= n; i++)
	{
		int num;
		scanf("%d", &num);
		if (num < k)
			++rak;
	}
	for (int i = 1; i <= m; i++)
	{
		int num;
		scanf("%d", &num);
		G[i].push_back(-1);
		a[i] = rak - num;
		int x;
		for (int j = 1; j <= num; j++)
		{
			cin >> x;
			G[i].push_back(x);
			if (x > k)
				--rak;
		}
	}
	build(1, 1, m);
	while (q--)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		if (x < m)
		{
			if (z > k && k > G[x][y])
				update(1, 1, m, x + 1, m, -1);
			if (z < k && k < G[x][y])
				update(1, 1, m, x + 1, m, 1);
		}
		G[x][y] = z;
		printf("%d\n", c[1] > 0);
	}
	return TIME;
}

猜你喜欢

转载自blog.csdn.net/weixin_43731933/article/details/102788904