QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#779595#7787. Maximum RatingKokomiWA 2ms9580kbC++143.3kb2024-11-24 20:13:072024-11-24 20:13:10

Judging History

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

  • [2024-11-24 20:13:10]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9580kb
  • [2024-11-24 20:13:07]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define endl "\n"

const int N = 4e5 + 10;
const ll INF = 0x3f3f3f3f3f3f3f;

ll n, m;
ll q;
vector<ll> a(N), tmp(N, 0);
map<ll, ll> mp;
struct node
{
  int l, r;
  ll cnt;
  ll sum;
} t[N << 2];
#define lu u << 1
#define ru u << 1 | 1

void build(int u, int l, int r)
{
  t[u] = {l, r, 0, 0};
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  build(lu, l, mid);
  build(ru, mid + 1, r);
}

void upd(int u, int pos, ll val)
{
  if (t[u].l == t[u].r)
  {
    t[u].cnt++;
    t[u].sum += val;
    return;
  }
  int mid = (t[u].l + t[u].r) >> 1;
  if (pos <= mid)
    upd(lu, pos, val);
  else
    upd(ru, pos, val);
  t[u].cnt = t[lu].cnt + t[ru].cnt;
  t[u].sum = t[lu].sum + t[ru].sum;
}

void del(int u, int pos, ll val)
{
  if (t[u].l == t[u].r)
  {
    t[u].cnt--;
    t[u].sum -= val;
    return;
  }
  int mid = (t[u].l + t[u].r) >> 1;
  if (pos <= mid)
    del(lu, pos, val);
  else
    del(ru, pos, val);
  t[u].cnt = t[lu].cnt + t[ru].cnt;
  t[u].sum = t[lu].sum + t[ru].sum;
}

int bs(int u, ll tar)
{
  if (t[u].sum <= tar)
    return t[u].r;
  if (t[u].l == t[u].r)
  {
    if (t[u].sum <= tar)
      return t[u].r;
    return t[u].l - 1;
  }
  if (t[lu].sum >= tar)
    return bs(lu, tar);
  return bs(ru, tar - t[lu].sum);
}

ll ask(int u, int l, int r)
{
  if (t[u].l >= l && t[u].r <= r)
    return t[u].cnt;
  int mid = (t[u].l + t[u].r) >> 1;
  ll res = 0;
  if (r > mid)
    res += ask(ru, l, r);
  if (l <= mid)
    res += ask(lu, l, r);
  return res;
}
ll askpre(int u, int l, int r)
{
  if (t[u].l >= l && t[u].r <= r)
    return t[u].sum;
  int mid = (t[u].l + t[u].r) >> 1;
  ll res = 0;
  if (r > mid)
    res += askpre(ru, l, r);
  if (l <= mid)
    res += askpre(lu, l, r);
  return res;
}
void solve()
{
  cin >> n >> q;
  set<ll> st;
  ll fu = 0;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    if (a[i] < 0)
      fu++;
    if (a[i] == 0)
      continue;
    st.insert(a[i]);
  }
  vector<pll> qry(q + 5);
  for (int i = 1; i <= q; i++)
  {
    cin >> qry[i].first >> qry[i].second;
    if (qry[i].second)
      st.insert(qry[i].second);
  }
  int tt = 1;
  for (auto e : st)
  {
    tmp[tt] = e;
    mp[e] = tt++;
  }
  build(1, 1, tt);
  for (int i = 1; i <= n; i++)
  {
    if (a[i])
      upd(1, mp[a[i]], a[i]);
  }
  for (int i = 1; i <= q; i++)
  {
    if (a[qry[i].first])
      del(1, mp[a[qry[i].first]], a[qry[i].first]);
    if (qry[i].second)
      upd(1, mp[qry[i].second], qry[i].second);
    if (a[qry[i].first] < 0)
      fu--;
    if (qry[i].second < 0)
      fu++;
    a[qry[i].first] = qry[i].second;
    int pos = bs(1, 0);
    ll pre = askpre(1, 1, pos);
    ll ans = ask(1, 1, pos);
    if (pre < 0 && pos < tt - 1)
    {
      ll qwq = tmp[pos + 1];
      ans += (-pre) / qwq;
    }
    if (n == 1000)
    {
      cout << "pos: " << pos << endl;
      cout << "ans: " << ans << endl;
      cout << "fu: " << fu << endl;
    }
    // cout << "pos: " << pos << endl;
    // cout << "cnt: "<<ans<<endl;
    cout << ans - fu + 1 << endl;
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int _ = 1;
  // cin>>_;
  while (_--)
    solve();
  return 0;
}

詳細信息

Test #1:

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

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: 9116kb

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: 9248kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 9296kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 9580kb

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:

pos: 636
ans: 946
fu: 1
946
pos: 319
ans: 0
fu: 1
0
pos: 319
ans: 0
fu: 1
0
pos: 319
ans: 0
fu: 1
0
pos: 636
ans: 915
fu: 1
915
pos: 636
ans: 592
fu: 1
592
pos: 636
ans: 983
fu: 1
983
pos: 319
ans: 0
fu: 1
0
pos: 319
ans: 0
fu: 1
0
pos: 636
ans: 899
fu: 1
899
pos: 636
ans: 809
fu: 1
809
pos: 319
ans...

result:

wrong output format Expected integer, but "pos:" found