QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#234684#7523. Partially Free MealnguyentunglamRE 0ms12884kbC++172.7kb2023-11-01 20:48:252023-11-01 20:48:25

Judging History

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

  • [2023-11-01 20:48:25]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:12884kb
  • [2023-11-01 20:48:25]
  • 提交

answer

#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

const int N = 2e5 + 10;

vector<int> rrh;

pair<int, int> a[N];

long long ans[N];

int n, m;

struct node {
  node * left;
  node * right;
  int cnt;
  long long sum;
  node () {
    left = right = nullptr;
    cnt = sum = 0;
  }

  void build(int l, int r) {
    if (l != r) {
      int mid = l + r >> 1;
      left = new node();
      right = new node();
      left -> build(l, mid);
      right -> build(mid + 1, r);
    }
  }

  void up(int l, int r, int pos, int val) {
    if (l == r) {
      cnt++;
      sum += val;
      return;
    }
    int mid = l + r >> 1;
    if (pos <= mid) {
      left = new node(*left);
      left -> up(l, mid, pos, val);
    }
    else {
      right= new node(*right);
      right -> up(mid + 1, r, pos, val);
    }
    cnt = left -> cnt + right -> cnt;
    sum = left -> sum + right -> sum;
  }

  long long get(int l, int r, int k) {
    if (!k) return 0;
    if (l == r) return sum / max(1, cnt) * min(k, cnt);
    assert(left);
    assert(right);
    int mid = l + r >> 1;
    if (k >= left -> cnt) return left -> sum + right -> get(mid + 1, r, k - left -> cnt);
    return left -> get(l, mid, k);
  }
};

node it[N];

void dnc (int l, int r, int from, int to) {
  if (l > r) return;
  int mid = l + r >> 1;
  int best = from;
  ans[mid] = 1e18;
  for(int j = max(mid, from); j <= to; j++) {
    long long tmp = it[j - 1].get(1, m, mid - 1) + a[j].first + a[j].second;
    if (ans[mid] > tmp) {
      ans[mid] = tmp;
      best = j;
    }
  }
  dnc(l, mid - 1, from, best);
  dnc(mid + 1, r, best, to);
}

int main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n;

  for(int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;

  sort(a + 1, a + n + 1, [] (const pair<int, int> &x, const pair<int, int> &y) {
    if (x.second != y.second) return x.second < y.second;
    return x.first < y.first;
  });

  for(int i = 1; i <= n; i++) rrh.push_back(a[i].first);

  sort(all(rrh));
  rrh.resize(unique(all(rrh)) - rrh.begin());
  m = rrh.size();

  it[0].build(1, m);

  for(int i = 1; i <= 2; i++) {
    int pos = upper_bound(all(rrh), a[i].first) - rrh.begin();
    it[i] = it[i - 1];
    it[i].up(1, m, pos, a[i].first);
  }

  dnc(1, n, 1, n);

  for(int i = 1; i <= n; i++) cout << ans[i] << endl;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Runtime Error

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:


result: