QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#258943#7750. Revenge on My Bosshos_lyricCompile Error//C++143.2kb2023-11-20 14:26:572023-11-20 14:26:58

Judging History

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

  • [2023-11-20 14:26:58]
  • 评测
  • [2023-11-20 14:26:57]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


/*
  (sum(B) + \sum (a[j] - b[j]) + a[i]) c[i] <= t
  prefix: a[j] - b[j] < 0
*/

int N;
vector<Int> A, B, C;

Int S[2];
using Entry = pair<pair<Int, Int>, int>;
vector<Entry> E[2];

vector<int> anss[2];
bool check(Int thr, bool recover = false) {
  for (int h = 0; h < 2; ++h) {
    vector<pair<Int, Entry>> ps;
    for (const Entry &e : E[h]) {
      ps.emplace_back(thr / C[e.second] - S[h] - e.first.second, e);
    }
    sort(ps.begin(), ps.end(), greater<pair<Int, Entry>>{});
    Int now = 0;
    if (recover) {
      anss[h].clear();
    }
    for (const auto &p : ps) {
      if (now <= p.first) {
        now += p.second.first.first;
        if (recover) {
          anss[h].push_back(p.second.second);
        }
      } else {
        return false;
      }
    }
  }
  if (recover) {
    reverse(anss[1].begin(), anss[1].end());
    anss[0].insert(anss[0].end(), anss[1].begin(), anss[1].end());
  }
  return true;
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d", &N);
    A.resize(N);
    B.resize(N);
    C.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
    }
    
    for (int h = 0; h < 2; ++h) {
      S[h] = 0;
      E[h].clear();
    }
    for (int i = 0; i < N; ++i) {
      S[0] += B[i];
      S[1] += A[i];
      if (A[i] - B[i] <= 0) {
        E[0].emplace_back(make_pair(A[i] - B[i], A[i]), i);
      } else {
        E[1].emplace_back(make_pair(B[i] - A[i], B[i]), i);
      }
    }
    
    Int lo = 0, hi = 1LL << 60;
    for (; lo + 1 < hi; ) {
      const Int mid = (lo + hi) / 2;
      (check(mid) ? hi : lo) = mid;
    }
    check(hi, true);
    
    assert((int)anss[0][j].size() == N);
    for (int j = 0; j < N; ++j) {
      if (j) printf(" ");
      printf("%d", anss[0][j] + 1);
    }
    puts("");
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

In file included from /usr/include/c++/11/cassert:44,
                 from answer.code:1:
answer.code: In function ‘int main()’:
answer.code:111:25: error: ‘j’ was not declared in this scope; did you mean ‘jn’?
  111 |     assert((int)anss[0][j].size() == N);
      |                         ^
answer.code:82:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
answer.code:87:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   87 |       scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~