답안 #762423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762423 2023-06-21T11:45:33 Z Chal1shkan Meteors (POI11_met) C++14
74 / 100
5728 ms 48208 KB
//Bismillahir-Rahmanir-Rahim

# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 3e5 + 25;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
const ll P = 67;

using namespace std;

int n, m, q, tl[maxn], tr[maxn];
vector <int> boss[maxn];
int need[maxn], ans[maxn];
int l[maxn], r[maxn], a[maxn];
vector <int> check[maxn];

struct segtree
{
	ll t[maxn * 4];
	ll z[maxn * 4];
	void build (int v = 1, int tl = 1, int tr = m)
	{
		t[v] = z[v] = 0;
		if (tl == tr)
		{
			return;
		}	
		int tm = (tl + tr) >> 1;
		build (v * 2, tl, tm);
		build (v * 2 + 1, tm + 1, tr);
	}		
	void push (int v, int tl, int tr)
	{
		if (z[v] && tl != tr)
		{
			int tm = (tl + tr) >> 1;
			t[v * 2] += z[v] * 1LL * (tm - tl + 1);
			t[v * 2 + 1] += z[v] * 1LL * (tr - tm);
			z[v * 2] += z[v];
			z[v * 2 + 1] += z[v];
			z[v] = 0;
		}
	}
	void update (int l, int r, int x, int v = 1, int tl = 1, int tr = m)
	{
		push(v, tl, tr);
		if (tr < l || r < tl) return;
		if (l <= tl && tr <= r)
		{
			t[v] += x * 1LL * (tr - tl + 1);
			z[v] += x;
			return;
		}
		int tm = (tl + tr) >> 1;
		update(l, r, x, v * 2, tl, tm);
		update(l, r, x, v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
	int get (int pos, int v = 1, int tl = 1, int tr = m)
	{
		push(v, tl, tr);
		if (tl == tr)
		{
			return t[v];
		}
		int tm = (tl + tr) >> 1;
		if (pos <= tm)
			return get(pos, v * 2, tl, tm);
		else
			return get(pos, v * 2 + 1, tm + 1, tr);
	}
} t;

void ma1n (/* SABR */)
{
	cin >> n >> m;
	for (int i = 1; i <= m; ++i)
	{
		int owner;
		cin >> owner;
		boss[owner].pb(i);
	}
	for (int i = 1; i <= n; ++i)
	{
		cin >> need[i];
	}
	cin >> q;
	for (int i = 1; i <= q; ++i)
	{
		cin >> l[i] >> r[i] >> a[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		tl[i] = 1, tr[i] = q, ans[i] = -1;
	}
	bool boo = 1;
	while (boo)
	{
		boo = 0;
		t.build();
		for (int i = 1; i <= n; ++i)
		{
			if (tl[i] <= tr[i])
			{
				check[(tl[i] + tr[i]) >> 1].pb(i);
			}
//			cout << tl[i] << ' ' << tr[i] << nl;
		}
		for (int i = 1; i <= q; ++i)
		{
			if (l[i] <= r[i])
			{
				t.update(l[i], r[i], a[i]);
			}
			else
			{
				t.update(l[i], m, a[i]);
				t.update(1, r[i], a[i]);
			}
			while (!check[i].empty())
			{
				boo = 1;
				int id = check[i].back();
				check[i].pop_back();
				ll sum = 0;
				for (int x : boss[id])
				{
					sum += t.get(x);
					if (sum >= need[id]) break;
				}
				if (sum >= need[id])
				{
					tr[id] = i - 1;
					ans[id] = i;
				}
				else
				{
					tl[id] = i + 1;
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		if (ans[i] == -1)
		{
			cout << "NIE" << nl;
		}
		else
		{
			cout << ans[i] << nl;
		}
	}
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}

// 998batrr | BbIWEJI 3A TObOU!!!
// tourist  | BbIWEJI 3A TObOU!!!
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14420 KB Output is correct
2 Correct 13 ms 14548 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14420 KB Output is correct
2 Correct 11 ms 14452 KB Output is correct
3 Correct 12 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 450 ms 18088 KB Output is correct
2 Correct 530 ms 19908 KB Output is correct
3 Correct 522 ms 19464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 499 ms 19020 KB Output is correct
2 Correct 506 ms 18984 KB Output is correct
3 Correct 478 ms 20008 KB Output is correct
4 Correct 77 ms 18368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 18368 KB Output is correct
2 Correct 339 ms 20552 KB Output is correct
3 Correct 228 ms 15180 KB Output is correct
4 Correct 486 ms 19968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 17420 KB Output is correct
2 Correct 435 ms 19068 KB Output is correct
3 Correct 458 ms 17700 KB Output is correct
4 Correct 531 ms 21240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5728 ms 48208 KB Output is correct
2 Incorrect 2432 ms 35768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5696 ms 47028 KB Output is correct
2 Incorrect 1348 ms 36348 KB Output isn't correct
3 Halted 0 ms 0 KB -