QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#403#201520#21703. 【NOIP Round #4】治病ytb2024zfs732Failed.2023-10-05 23:12:382023-10-05 23:12:40

Details

Extra Test:

Accepted
time: 7ms
memory: 89544kb

input:

1245 633
324289 939521 905537 114273 762241 824417 330323 808525 704000 532033 664201 694801 584529 56013 347925 409089 708417 694625 680385 581377 225882 785025 3457 874049 968521 67585 385729 500641 311141 843414 454737 534081 466497 80129 824897 387553 974497 773121 758441 704769 183105 481057 87...

output:

957363140965 737452188915 908302653933 944377402394 926935752822 956534138822 940576156749 956145923858 958537289665 958606871593 958437628708 958434760060 957289637064 958487710189 958606871593 958596901162 958606871593 958599807088 958473100340 958170699255 958604999407 958124013705 958606871593 9...

result:

ok 1245 numbers

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201520#21703. 【NOIP Round #4】治病zfs732100 ✓2140ms125244kbC++142.0kb2023-10-05 14:56:102023-10-05 14:56:10

answer

#include<bits/stdc++.h>

#define REP(i, l, r) for (int i = l; i <= r; i++)
#define PER(i, r, l) for (int i = r; i >= l; i--)

using namespace std;

mt19937 engine(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
T rand(T l, T r) { return uniform_int_distribution<>(l, r)(engine); }

const int maxN = 1e6 + 1;

int n, m, sL[maxN], sR[maxN], w[maxN];
long long ans[maxN], rAns;
vector<int> a[maxN];

class segmentTree {
	struct node {
		int l, r, sum, full;
	} tree[maxN << 2];
	
#define LS(u) (u << 1)
#define RS(u) (u << 1 | 1)
#define L(u) tree[u].l
#define R(u) tree[u].r
#define S(u) tree[u].sum
#define F(u) tree[u].full

	inline void pushUp(int u) {
		if (F(u)) S(u) = R(u) - L(u) + 1;
		else if (L(u) == R(u)) S(u) = 0;
		else S(u) = S(LS(u)) + S(RS(u));
	}
	
	void build(int l, int r, int u = 1) {
		if (l > r) return;
		L(u) = l, R(u) = r, F(u) = S(u) = 0;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build(l, mid, LS(u)), build(mid + 1, r, RS(u));
	}
	
public:
	segmentTree() { build(1, maxN - 1); }
	
	void modify(int l, int r, int x, int u = 1) {
		if (l <= L(u) && R(u) <= r)
			return F(u) += x, pushUp(u), void();
		int mid = (L(u) + R(u)) >> 1;
		if (l <= mid) modify(l, r, x, LS(u));
		if (mid < r) modify(l, r, x, RS(u));
		pushUp(u);
	}
	
	int query() { return S(1); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n >> m;
	segmentTree tr;
	REP(i, 1, m) cin >> w[i];
	REP(i, 1, n) {
		int k, x;
		cin >> sL[i] >> sR[i] >> k;
		while (k--)
			cin >> x, a[x].emplace_back(i);
	}
	REP(i, 1, m) {
		for (auto v: a[i]) tr.modify(sL[v], sR[v], 1);
		int lst = tr.query();
		rAns += 1LL * lst * w[i];
		for (auto v: a[i]) {
			tr.modify(sL[v], sR[v], -1);
			int res = lst - tr.query();
			ans[v] += 1LL * res * w[i];
			tr.modify(sL[v], sR[v], 1);
		}
		for (auto v: a[i]) tr.modify(sL[v], sR[v], -1);
	}
	REP(i, 1, n) cout << rAns - ans[i] << " \n"[i == n];

	return 0;
}