QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666210 | #7787. Maximum Rating | crashed | WA | 1ms | 5956kb | C++14 | 1.5kb | 2024-10-22 17:04:20 | 2024-10-22 17:04:27 |
Judging History
answer
#include <bits/stdc++.h>
#define RANGE 1, 1e9
const int MAXN = 2e5 + 5, MAXS = 5e6 + 5;
long long su[MAXS];
int lch[MAXS], rch[MAXS], siz[MAXS];
int ntot = 0, rt = 0;
int a[MAXN];
int n, q;
void update( int &x, const int &l, const int &r, const int &p, const int &delt ) {
if( ! x ) x = ++ ntot;
su[x] += delt * p, siz[x] += delt;
if( l < r ) {
int mid = ( l + r ) >> 1;
p <= mid ? update( lch[x], l, mid, p, delt ) :
update( rch[x], mid + 1, r, p, delt );
}
}
int count_first( const int &x, const int &l, const int &r, const long long &lim ) {
if( l == r ) return l == 0 ? siz[x] : lim / l;
else {
int mid = ( l + r ) >> 1;
return lim < su[lch[x]] ? count_first( lch[x], l, mid, lim ) :
siz[lch[x]] + count_first( rch[x], mid + 1, r, lim - su[lch[x]] );
}
}
int main() {
// freopen( "K.in", "r", stdin );
scanf( "%d %d", &n, &q );
long long negSum = 0;
auto modify = [&] ( const int &x, const int &c ) {
if( a[x] <= 0 ) negSum += - c * a[x];
else update( rt, RANGE, a[x], c );
};
for( int i = 1 ; i <= n ; i ++ )
scanf( "%d", a + i ), modify( i, +1 );
while( q -- ) {
int x, v;
scanf( "%d %d", &x, &v );
modify( x, -1 ), a[x] = v, modify( x, +1 );
printf( "%d\n", count_first( rt, RANGE, negSum ) + 1 );
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5892kb
input:
3 5 1 2 3 3 4 2 -2 1 -3 3 1 2 1
output:
1 2 2 2 3
result:
ok 5 number(s): "1 2 2 2 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5956kb
input:
3 5 1 2 3 3 4 2 -2 1 3 3 1 2 1
output:
1 2 1 2 1
result:
ok 5 number(s): "1 2 1 2 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5880kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3892kb
input:
1 1 -1000000000 1 -1000000000
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'