QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298109#4636. Optimal Assortmentdefyers#WA 217ms23996kbC++171.9kb2024-01-05 17:49:192024-01-05 17:49:19

Judging History

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

  • [2024-01-05 17:49:19]
  • 评测
  • 测评结果:WA
  • 用时:217ms
  • 内存:23996kb
  • [2024-01-05 17:49:19]
  • 提交

answer

#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC targetr("avx2")

using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define int long long

const int N = 2e5 + 11;
const int V = 1e6 + 11;

int v[N], l[N], r[N];

struct node{
	int w, s;
};

int n, m; 

struct BIT{
	int bit[V], sum = 0;
	void add(int p, int v){ sum += v; for(int i = p; i < V; i += i & -i) bit[i] += v; }
	int qry(int p){ int ret = 0; for(int i = p; i; i -= i & -i) ret += bit[i]; return ret; }
} bit0, bit1;

void add(int profit, int quantity){
	bit0.add(profit, quantity);
	bit1.add(profit, quantity * profit);
}

void query(){
	int p = 0;
	int P = 0, Q = 1;
	for(int j = 19; j >= 0; j--){
		if(p + (1 << j) < V){
			int s0 = bit0.sum - bit0.qry(p + (1 << j) - 1);
			int s1 = bit1.sum - bit1.qry(p + (1 << j) - 1);
			// cout << s1 << ' ' << (s0 + r[0]) << ' ' << p + (1 << j) << '\n';
			if(s1 != 0 && s1 >= (s0 + r[0]) * (p + (1 << j))){
				p += (1 << j);
				P = s1; Q = s0 + r[0];
			}
		}
	}

	int g = gcd(P, Q);
	P /= g; Q /= g;
	cout << P << '/' << Q << '\n';
}

void solve(int TC) {
	cin >> n >> m;
	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++){
		add(v[i], l[i]);
	}
	query();
	for(int i = 0; i < m; i++){
		int t; cin >> t;
		if(t == 1){
			int x, y, z; cin >> x >> y >> z;
			if(v[x] != 0) add(v[x], -l[x]);
			l[x] = y, r[x] = z;
			if(v[x] != 0) add(v[x], l[x]);
		}else{
			int x, y; cin >> x >> y;
			assert(x >= 1);
			add(v[x], -l[x]);
			v[x] = y;
			add(v[x], l[x]);
		}
		query();
	}
}

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(10);

	int t = 1;
	// cin >> t;
	for (int i = 1; i <= t; i++) {
		solve(i);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 217ms
memory: 23996kb

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:

wrong answer 142nd lines differ - expected: '312363185627235/313871594', found: '312387878380763/313896406'