QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#61045 | #4636. Optimal Assortment | chiranko# | WA | 277ms | 55476kb | C++ | 2.6kb | 2022-11-09 17:11:44 | 2022-11-09 17:11:45 |
Judging History
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];\
int read()
{
int x = 0, fl = 1;
char ch = getchar();
while(!isdigit(ch) && ch != '-')
ch = getchar();
if(ch == '-')
fl = -1;
while(isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return x * fl;
}
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;
printf("%d/%d\n", ansa, ansb);
}
int main()
{
// freopen("test.in", "r", stdin);
// freopen("test.out", "w", stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);
n = read(), m = read();
len = 1e6;
for(int i = 1; i <= n; ++i)
V[i] = read();
for(int i = 0; i <= n; ++i)
L[i] = read();
for(int i = 0; i <= n; ++i)
R[i] = read();
for(int i = 1; i <= n; ++i)
tmp[V[i]] += L[i];
build(1, 0, len);
work();
while(m--){
int opt, x, y, z;
opt = read(), x = read(), y = read();
if(opt == 1){
z = read();
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: 4ms
memory: 46532kb
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: 277ms
memory: 55476kb
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:
1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 1693774621/313072603 169377...
result:
wrong answer 1st lines differ - expected: '311567211361053/313072603', found: '1693774621/313072603'