QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61040#4636. Optimal Assortmentchiranko#TL 0ms21680kbC++142.0kb2022-11-09 16:34:362022-11-09 16:34:38

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 16:34:38]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:21680kb
  • [2022-11-09 16:34:36]
  • 提交

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 = 1e6 + 5;

int n, m, len;

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

LL ansa, ansb, tl, tvl;

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



void pushup(int x)
{
	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);
	pushup(x);
}

void query(int x, int l, int r)
{
	if(l == r){
		ansa = tvl;
		ansb = tl + R[0];
		return;
	}
	
	int mid = (l + r) >> 1;
	DB t = 1.0 * (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){
		update(1, 0, len, V[i], L[i], R[i], 1);
	}
	
	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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 21680kb

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: