QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#61049#4636. Optimal Assortmentchiranko#TL 4ms46472kbC++142.3kb2022-11-09 17:29:222022-11-09 17:29:25

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-09 17:29:25]
  • 评测
  • 测评结果:TL
  • 用时:4ms
  • 内存:46472kb
  • [2022-11-09 17:29:22]
  • 提交

answer

#include<bits/stdc++.h>
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

using namespace std;
typedef long long LL;
typedef double DB;

const int maxn = 2e6 + 5;

int n, m, len;

LL tmp[maxn];
LL suml[maxn << 2], sumvl[maxn << 2];

LL ansa, ansb, tl, tvl;

int V[maxn], L[maxn], R[maxn];


void build(int x, int l, int r)
{
	if(l == r){
		suml[x] = tmp[l];
		sumvl[x] = 1LL * tmp[l] * l;
		return;
	}
	
	int mid = (l + r) >> 1;
	build(ls(x), l, mid), build(rs(x), mid + 1, r);
	suml[x] = suml[ls(x)] + suml[rs(x)];
	sumvl[x] = sumvl[ls(x)] + sumvl[rs(x)];
}

void update(int x, int l, int r, int pos, int wl, int wr, int fl)
{
	if(l == r){
		suml[x] += wl * fl;
		sumvl[x] += 1LL * l * wl * fl;
		return;
	}
	
	int mid = (l + r) >> 1;
	if(pos <= mid)
		update(ls(x), l, mid, pos, wl, wr, fl);
	else
		update(rs(x), mid + 1, r, pos, wl, wr, fl);
	suml[x] = suml[ls(x)] + suml[rs(x)];
	sumvl[x] = sumvl[ls(x)] + sumvl[rs(x)];
}

void query(int x, int l, int r)
{
	if(l == r){
		ansa = tvl;
		ansb = tl + R[0];
		return;
	}
	
	int mid = (l + r) >> 1;
	LL t = (tvl + sumvl[rs(x)]) - 1LL * (mid + 1) * (tl + suml[rs(x)] + R[0]);
	if(t > 0)
		query(rs(x), mid + 1, r);
	else{
		tvl += sumvl[rs(x)];
		tl += suml[rs(x)];
		query(ls(x), l, mid);
	}
}

void work()
{
	ansa = 0, ansb = 1;
	tl = 0, tvl = 0;
	query(1, 0, len);
	if(!ansb)
		ansa = 0, ansb = 1;
	auto t = __gcd(ansa, ansb);
	ansa /= t, ansb /= t;
	cout << ansa << "/" << ansb << endl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	len = 1e6;
	for(int i = 1; i <= n; ++i)
		cin >> V[i];
	for(int i = 0; i <= n; ++i)
		cin >> L[i];
	for(int i = 0; i <= n; ++i)
		cin >> R[i];
	for(int i = 1; i <= n; ++i)
		tmp[V[i]] += L[i];
	build(1, 0, len);
	
	work();
	while(m--){
		int opt, x, y, z;
		cin >> opt >> x >> y;
		if(opt == 1){
			cin >> z;
			if(x){
				update(1, 0, len, V[x], L[x], R[x], -1);
				L[x] = y, R[x] = z;
				update(1, 0, len, V[x], L[x], R[x], 1);
			}
			else{
				L[x] = y, R[x] = z;
			}
			
		}
		else{
			if(x){
				update(1, 0, len, V[x], L[x], R[x], -1);
				V[x] = y;
				update(1, 0, len, V[x], L[x], R[x], 1);
			}
			else{
				V[x] = y;
			}
		}
		work();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 46472kb

input:

2 5
4 2
4 3 2
4 3 2
2 1 2
1 1 2 3
1 0 0 0
1 1 0 0
1 2 0 0

output:

16/9
10/9
1/1
2/1
2/1
0/1

result:

ok 6 lines

Test #2:

score: -100
Time Limit Exceeded

input:

200000 200000
959139 199252 470888 74578 802746 396295 386884 721198 628655 722503 207868 647942 87506 792718 761498 917727 843338 908043 952768 268783 375312 414369 319712 96230 277106 168102 263554 936674 246545 667941 198849 268921 191459 436316 134606 802932 515506 837311 465964 394766 17626 650...

output:

311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
31156721136105...

result: