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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章