QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#609192 | #7787. Maximum Rating | downfall | WA | 2ms | 11808kb | C++17 | 3.5kb | 2024-10-04 11:10:19 | 2024-10-04 11:10:22 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define frep(i, l, r) for (int i = l; i >= r; i--)
#define eb emplace_back
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int N = 2e5 + 3;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int a[N], b[N], d[N];
int n, q;
int num1; // 正数个数
int num2; // 负数个数'
int num3; // 0个数
struct opt
{
int pos, val;
} c[N];
struct SegmentTree
{
int l, r;
int sum, cnt;
} tr[N << 2];
#define ls (i << 1)
#define rs (i << 1 | 1)
void pushup(int i)
{
tr[i].sum = tr[ls].sum + tr[rs].sum;
tr[i].cnt = tr[ls].cnt + tr[rs].cnt;
}
void build(int i, int l, int r)
{
if (l == r)
{
return;
}
tr[i] = {l, r, 0, 0};
int mid = (l + r) >> 1;
build(ls, l, mid), build(rs, mid + 1, r);
pushup(i);
}
void insert(int i, int p, int x)
{
if (tr[i].l == tr[i].r)
{
tr[i].sum += a[p] * x;
tr[i].cnt += x;
return;
}
int mid = (tr[i].l + tr[i].r) >> 1;
if (b[p] <= mid)
insert(ls, p, x);
else
insert(rs, p, x);
pushup(i);
}
void modify(int i, int p, int x)
{
if (tr[i].l == tr[i].r)
{
tr[i].sum = x;
return;
}
int mid = (tr[i].l + tr[i].r) >> 1;
if (p <= mid)
modify(ls, p, x);
else
modify(rs, p, x);
pushup(i);
}
int query(int i, int sum)
{
if (tr[i].l == tr[i].r)
{
return tr[i].cnt;
}
int mid = (tr[i].l + tr[i].r) >> 1;
if (sum + tr[ls].sum >= 0)
return query(ls, sum);
else
return tr[ls].cnt + query(rs, sum + tr[ls].sum);
}
void solve()
{
vector<int> ve;
cin >> n >> q;
rep(i, 1, n)
{
cin >> a[i];
ve.pb(a[i]);
if (a[i] > 0)
num1++;
else if (a[i] < 0)
num2++;
else
num3++;
}
rep(i, 1, q)
{
int x, y;
cin >> x >> y;
c[i] = (opt){x, y};
ve.push_back(y);
}
sort(ve.begin(), ve.end());
ve.erase(unique(ve.begin(), ve.end()), ve.end());
rep(i, 1, n) b[i] = lower_bound(ve.begin(), ve.end(), a[i]) - ve.begin() + 1;
rep(i, 1, q) d[i] = lower_bound(ve.begin(), ve.end(), c[i].val) - ve.begin() + 1;
int p = ve.size();
build(1, 1, p);
rep(i, 1, n) insert(1, i, 1);
rep(i, 1, q)
{
int x = c[i].pos, y = c[i].val;
if (a[x] > 0)
num1--;
else if (a[x] < 0)
num2--;
else
num3--;
if (y > 0)
num1++;
else if (y < 0)
num2++;
else
num3++;
insert(1, x, -1);
a[x] = y, b[x] = d[i];
insert(1, x, 1);
if (tr[1].sum < 0)
{
cout << num1 + 1 << endl;
}
else
{
int t = query(1, 0);
if (t == 0)
cout << 1 << endl;
else
{
cerr << t << " " << tr[1].sum << endl;
int w = t - 1 - num2 - num3;
cout << w + 1 << endl;
}
}
}
}
signed main()
{
IOS;
int T = 1;
// cin >> T;
while (T--)
solve();
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11808kb
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: 2ms
memory: 9684kb
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: 0ms
memory: 9680kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 9744kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 10064kb
input:
1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
999 1 1 1 999 999 999 1 1 999 999 1 999 999 1 1 999 1 1 999 999 1 999 1 1 999 999 1 1 999 999 999 1 999 999 1 999 999 1 1 1 999 999 999 999 999 1 999 999 1 1 999 999 999 999 999 999 1 999 1 999 999 999 999 1 1 999 1 1 1 1 1 1 1 1 1 999 999 999 999 1 999 999 1 999 999 1 999 1 1 999 1 1 1 1 999 1 1 1 ...
result:
wrong answer 1st numbers differ - expected: '946', found: '999'