QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353762#7520. Monster GeneratorSampsonYWWA 1ms4060kbC++144.3kb2024-03-14 16:01:062024-03-14 16:01:06

Judging History

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

  • [2024-03-14 16:01:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4060kb
  • [2024-03-14 16:01:06]
  • 提交

answer

#include <bits/stdc++.h>
#define db double
#define re register
#define il inline
#define ll long long
#define ull unsigned ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
using namespace std;
#define N 10005
int n; ll m;
ll a[N], ad[N], b[N], bd[N];
i128 A[N], B[N];
struct node {
  i128 k, b;
  il i128 F(i128 x) {return k * x + b;}
  // il ull calc(i128 L, i128 R) {
  //   return (ull)k * (ull)((L + R) * (R - L + 1) / 2) + (ull)(R - L + 1) * (ull)b;
  // }
  il i128 calc(i128 L, i128 R) {
    return k * ((L + R) * (R - L + 1) / 2) + (R - L + 1) * b;
  }
  il bool operator < (const node &t) const {return k == t.k ? b < t.b : k < t.k;}
  il node operator - (const node &t) const {return {k - t.k, b - t.b};}
  il i128 operator * (const node &t) const {return k * t.b - b * t.k;}
} p[N], v[N], h[N];
il bool chk(node A, node B) {return A * B <= 0;}
il i128 calc(i128 lim) {
  FOR(i, 0, n) v[i] = p[i];
  sort(v, v + n + 1); int top = 0;
  FOR(i, 0, n) {
    while(top > 1 && chk(v[i] - h[top], h[top] - h[top - 1])) --top;
    h[++top] = v[i];
  }
  // FOR(i, 1, top) cout << (ll)h[i].k << "*x+" << (ll)h[i].b << ", "; cout << "\n";
  int now = 0; i128 p = 0, ans = 0;
  FOR(p, 0, lim) {
    i128 s = 0;
    FOR(i, 1, top) s = max(s, h[i].F(p));
    ans += s;
  }
  // while(p <= lim) {
  //   while(now < top && h[now].F(p) <= h[now + 1].F(p)) ++now;
  //   if(now == top) {ans += h[now].calc(p, lim); break;}
  //   i128 r = p;
  //   ROF(i, 120, 0) {
  //     i128 nr = r + (i128)1 << i; if(nr > lim) continue;
  //     if(h[now].F(nr) < h[now + 1].F(nr)) r = nr;
  //   }
  //   ans += h[now].calc(p, r), ++now, p = r + 1;
  // }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  FOR(i, 1, n) cin >> a[i] >> ad[i] >> b[i] >> bd[i];
  vector<ll> pos;
  FOR(i, 1, n) {
    if(a[i] > b[i] && ad[i] < bd[i]) {
      ll p = (a[i] - b[i]) / (bd[i] - ad[i]);
      pos.eb(p), pos.eb(p + 1);
    }
    if(a[i] == b[i] && ad[i] != bd[i])
      pos.eb(0), pos.eb(1);
    if(a[i] < b[i] && ad[i] > bd[i]) {
      ll p = (b[i] - a[i]) / (ad[i] - bd[i]);
      pos.eb(p), pos.eb(p + 1);
    }
  }
  FOR(i, 1, n) FOR(j, i + 1, n) {
    if(a[i] > a[j] && ad[i] < ad[j]) {
      ll p = (a[i] - a[j]) / (ad[j] - ad[i]);
      pos.eb(p), pos.eb(p + 1);
    }
    if(a[i] == a[j] && ad[i] != ad[j])
      pos.eb(0), pos.eb(1);
    if(a[i] < a[j] && ad[i] > ad[j]) {
      ll p = (a[j] - a[i]) / (ad[i] - ad[j]);
      pos.eb(p), pos.eb(p + 1);
    }
    if(b[i] > b[j] && bd[i] < bd[j]) {
      ll p = (b[i] - b[j]) / (bd[j] - bd[i]);
      pos.eb(p), pos.eb(p + 1);
    }
    if(b[i] == b[j] && bd[i] != bd[j])
      pos.eb(0), pos.eb(1);
    if(b[i] < b[j] && bd[i] > bd[j]) {
      ll p = (b[j] - b[i]) / (bd[i] - bd[j]);
      pos.eb(p), pos.eb(p + 1);
    }
  }
  pos.eb(0);
  sort(ALL(pos)), pos.erase(unique(ALL(pos)), pos.end());
  while(pos.back() > m) pos.pop_back(); pos.eb(m + 1);
  i128 ans = 0;
  FOR(i, 1, SZ(pos) - 1) {
    i128 L = pos[i - 1], R = pos[i] - 1;
    FOR(i, 1, n) A[i] = a[i] + L * ad[i], B[i] = b[i] + L * bd[i];
    vector<int> Po, Ne;
    FOR(i, 1, n) if(A[i] < B[i]) Po.eb(i); else Ne.eb(i);
    sort(ALL(Po), [](int x, int y) {return A[x] < A[y];});
    sort(ALL(Ne), [](int x, int y) {return B[x] > B[y];});
    for(auto x : Po) cout << x << " "; for(auto x : Ne) cout << x << " "; cout << "\n";
    FOR(i, 1, n) cout << (ll)A[i] << " " << (ll)B[i] << "\n";
    int now = 0, pre = 0;
    for(auto x : Po) {
      ++now;
      p[now].k = p[now - 1].k + ad[x] - bd[pre];
      p[now].b = p[now - 1].b + A[x] - B[pre];
      pre = x;
    }
    for(auto x : Ne) {
      ++now;
      p[now].k = p[now - 1].k + ad[x] - bd[pre];
      p[now].b = p[now - 1].b + A[x] - B[pre];
      pre = x;
    }
    FOR(i, 0, n) cout << (ll)p[i].k << "*x+" << (ll)p[i].b << ", "; cout << "\n";
    ans += calc(R - L);
  }
  cout << (ll)ans;
  cerr << 1.0 * clock() / CLOCKS_PER_SEC;
  return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4060kb

input:

3 5
3 1 5 2
4 2 1 3
1 9 100 1

output:

3 1 2 
3 5
4 1
1 100
0*x+0, 9*x+1, 9*x+-96, 9*x+-97, 
1 3 2 
4 7
6 4
10 101
0*x+0, 1*x+4, 8*x+7, 9*x+-88, 
1 3 2 
6 11
10 10
28 103
0*x+0, 1*x+6, 8*x+23, 9*x+-70, 
1 2 3 
7 13
12 13
37 104
0*x+0, 1*x+7, 1*x+6, 7*x+30, 
1 2 3 
8 15
14 16
46 105
0*x+0, 1*x+8, 1*x+7, 7*x+37, 
113

result:

wrong answer 1st lines differ - expected: '113', found: '3 1 2 '