QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#346303#7520. Monster GeneratorMiniLongWA 1ms3652kbC++145.8kb2024-03-08 10:35:422024-03-08 10:35:42

Judging History

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

  • [2024-03-08 10:35:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3652kb
  • [2024-03-08 10:35:42]
  • 提交

answer

#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef __int128_t LL;
typedef pair<ll, ll> PII;
namespace fastio{
    char ibuf[50007],*p1 = ibuf, *p2 = ibuf;
    #ifdef ONLINE_JUDGE
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 50007, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244353;
    ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 205, M = 1e5 + 5;
typedef unsigned long long ull;
ll n, m, cnt, p[M];
struct node{
    ll a, b, da, db;
}a[N];
int b[N];
bool check(ll x, ll y, LL mid){
    LL xa = a[x].a + mid * a[x].da, xb = a[x].b + mid * a[x].db;
    LL ya = a[y].a + mid * a[y].da, yb = a[y].b + mid * a[y].db;
    bool ok = (xb - xa > 0 && yb - ya <= 0);
    if(xb - xa <= 0 && yb - ya <= 0) ok |= (xb > yb);
    if(xb - xa > 0 && yb - ya > 0) ok |= (xa < ya);
    return ok;
}
void gett(ll x, ll y){
    ll cur = 0;
    if(a[x].db != a[y].db){
        cur = (a[y].b - a[x].b) / (a[x].db - a[y].db) + 1;
        if(cur >= 0 && cur <= m) p[++cnt] = cur;
    }
    if(a[x].da != a[y].da){
        cur = (a[y].a - a[x].a) / (a[x].da - a[y].da) + 1;
        if(cur >= 0 && cur <= m) p[++cnt] = cur;
    }
    if(a[x].da != a[x].db){
        cur = (a[x].b - a[x].a) / (a[x].da - a[x].db) + 1;
        if(cur >= 0 && cur <= m) p[++cnt] = cur;
    }
    if(a[y].da != a[y].db){
        cur = (a[y].b - a[y].a) / (a[y].da - a[y].db) + 1;
        if(cur >= 0 && cur <= m) p[++cnt] = cur;
    }
}
ull ans;
void solve(ll tl, ll tr){
    _rep(i, 1, n) b[i] = i;
    sort(b + 1, b + 1 + n, [&](int x, int y){
        return check(x, y, tl);
    });
    // debug("check [%d,%d,%d] :%d\n", 2, 3, tl, check(2, 3, tl));
    // debug("solve [%d,%d]\n", tl, tr);
    // _rep(i, 1, n) debug("%d ", b[i]); debug("\n");
    LL k = 0, t = 0;
    vector<pair<LL, LL> > h;
    _rep(i, 1, n){
        k += a[b[i]].da, t += a[b[i]].a;
        h.pb({k, t});
        // debug("(%d,%d) ", (ll)k, (ll)t);
        k -= a[b[i]].db, t -= a[b[i]].b;
    }
    // debug("\n");
    sort(h.begin(), h.end());
    vector<pair<LL, LL> > g;
    g.pb(*h.begin());
    int len = 1;
    _rep(i, 1, h.size() - 1){
        while(len > 1 && ((g[len - 1].se - h[i].se) * (g[len - 1].fi - g[len - 2].fi) < (g[len - 2].se - g[len - 1].se) * (h[i].fi - g[len - 1].fi)) || len && g[len - 1].fi == h[i].fi){
            len--;
            g.pop_back();
        }
        g.pb(h[i]);
        len++;
    }
    LL lst = tl;
    // for(auto &i : g) debug("(%d,%d) ", (ll)i.fi, (ll)i.se);
    // debug("\n");
    auto calc = [&](LL l, LL r, int id) -> ull{
        LL yl = g[id].fi * l + g[id].se, yr = g[id].fi * r + g[id].se;
        LL cur1 = (yl + yr), cur2 = r - l + 1;
        if(cur1 % 2 == 0) cur1 /= 2;
        else cur2 /= 2;
        ull res = ((ull)cur1) * ((ull)cur2);
        // debug("calc [%d,%d,id:%d] ans:%Ld | ", (ll)l, (ll)r, id, res);
        return res;
    };
    _rep(i, 0, len - 2){
        LL l = lst, r = (g[i + 1].se - g[i].se) / (g[i].fi - g[i + 1].fi);
        while(g[i].fi * r + g[i].se < g[i + 1].fi * r + g[i + 1].se) r--;
        // debug("r:%d\n", (ll)r);
        if(r > tr) r = tr;
        if(r < l) continue;
        ans += calc(l, r, i);
        lst = r + 1;
        if(lst > tr) break;
    }
    if(lst <= tr) ans += calc(lst, tr, len - 1);
    // debug("\n");
    // debug("-------------\n");
}
int main(){
    read(n, m);
    _rep(i, 1, n){
        read(a[i].a, a[i].da, a[i].b, a[i].db);
        _rep(j, 1, i - 1){
            gett(i, j);
        }
    }
    _rep(i, 0, m){
        _rep(j, 1, n) debug("(%d,%d) ", a[j].a + a[j].da * i, a[j].b + a[j].db * i);
        debug("\n");
    }
    p[++cnt] = m, p[++cnt] = 0;
    sort(p + 1, p + 1 + cnt);
    cnt = unique(p + 1, p + 1 + cnt) - p - 1;
    // _rep(i, 1, cnt) writes(p[i]); puts("");
    int lst = p[1];
    // _rep(i, 1, m) solve(i, i);
    _rep(i, 2, cnt) solve(lst, p[i] - 1), lst = p[i];
    solve(m, m);
    writeln(ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

input:

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

output:

113

result:

ok single line: '113'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

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

output:

35000000549999998

result:

ok single line: '35000000549999998'

Test #3:

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

input:

10 1000000000000000000
776874380544333 197 471391764744275 33
159838820333814 107 677112662750393 41
962335658276824 48 255593531071176 11
127404116579775 209 268525254990127 34
647620110614714 76 897947476313307 13
146196843402516 221 772928712898807 39
637929916804442 2 716937021892338 15
64200226...

output:

15084422478038399866

result:

wrong answer 1st lines differ - expected: '17883317185357051350', found: '15084422478038399866'