#2019-2020 ICPC, Asia Jakarta Regional Contest G题(线段树)

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个员工, 现在要对这些员工进行长达M年的考评, 每个员工都有各自唯一的贡献值, 先对第一个员工进行标记,考察该员工的情况。每年都有X个新员工加入, 意味着该公司贡献值最低的X个员工将被替换掉。 共有Q次询问操作, 每次将第a年的第b个员工的贡献值改为c(以后询问仍保持该修改), 问标记员工在M年后是否仍然留在公司中, 如果是输出1, 否则输出0

思路 :要想知道标记员工是否留在公司, 只要看他的地位是否一直保持在0以上(贡献值越大地位越大), 所以用线段树维护区间最小值即可, 首先通过原本公司的贡献情况得出标记员工的初始地位, 之后的M年,每次更新该员工的地位, 并通过M年建树, 查询时, 设更改的员工原来的贡献为K, 更改后的贡献为S, 标记员工的贡献为W, 若K < W && S > W(原来比他地位低更改后地位比他高了)则标记员工从i + 1年开始地位都 - 1, 若K > W && S < W(原来比他地位高更改后地位比他低了), 则标记员工从i + 1年开始地位都 + 1, 最后看线段树第一个结点的最小值是否 < 0就好

Accepted code

#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;

#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define MEM(x, b) memset(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))

typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 2e6 + 100;
const int INF = 0x3f3f3f3f;
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % MOD; b >>= 1; t = (t*t) % MOD; }return r; }

struct Tree
{
	int l, r, ans, lzy;
}t[MAXN * 4];
int p[MAXN], n, m, q, k, rak = 1;
vector <int> e[MAXN];
void Build(int rt, int l, int r) {
	t[rt].l = l, t[rt].r = r;
	if (l == r) { t[rt].ans = p[l]; return; }
	int mid = (l + r) >> 1; 
	Build(ls, l, mid);
	Build(rs, mid + 1, r); 
	t[rt].ans = min(t[ls].ans, t[rs].ans);
}
void Pushdown(int rt) {
	t[ls].lzy += t[rt].lzy, t[rs].lzy += t[rt].lzy;
	t[ls].ans += t[rt].lzy, t[rs].ans += t[rt].lzy;
	t[rt].lzy = 0;
}
void Update(int rt, int l, int r, int pos) {
	if (t[rt].l >= l && t[rt].r <= r) {
		t[rt].ans += pos;
		t[rt].lzy += pos;
		return;
	}
	int mid = (t[rt].l + t[rt].r) >> 1;
	if (t[rt].lzy) Pushdown(rt);
	if (mid < l) Update(rs, l, r, pos);
	else if (mid >= r) Update(ls, l, r, pos);
	else {
		Update(ls, l, mid, pos);
		Update(rs, mid + 1, r, pos);
	}
	t[rt].ans = min(t[ls].ans, t[rs].ans);
}

int main()
{
	cin >> n >> m >> q >> k;
	for (int i = 2; i <= n; i++) {
		int tmp; sc("%d", &tmp);
		if (tmp < k) rak++;  // 地位
	}
	for (int i = 1; i <= m; i++) {
		int T; sc("%d", &T); 
		p[i] = rak - T;
		for (int j = 0; j < T; j++) {
			int tmp; sc("%d", &tmp);
			if (tmp > k) rak--;
			e[i].push_back(tmp);
		}
	}
	Build(1, 1, m); 
	for (int i = 0; i < q; i++) {
		int xi, yi, zi; sc("%d %d %d", &xi, &yi, &zi);
		int tmp = e[xi][yi - 1];    // 原来的贡献
		e[xi][yi - 1] = zi;
		if (xi < m) {   
			if (tmp > k && zi < k) Update(1, xi + 1, m, 1);  
			else if (tmp < k && zi > k) Update(1, xi + 1, m, -1);
		}
		if (t[1].ans <= 0) cout << 0 << endl;
		else cout << 1 << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43851525/article/details/102870425