QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#110600#2560. Streetlightsxzggzh1WA 0ms3448kbC++172.2kb2023-06-02 22:31:232023-06-02 22:36:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-02 22:36:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3448kb
  • [2023-06-02 22:31:23]
  • 提交

answer

#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = (l); i <= (r); i++)
#define ROF(i, r, l) for(int i = (r); i >= (l); i--)
#define sz(a) int((a).size())
#define ll long long
#define lll __int128
#define ull unsigned long long
#define vi vector<int>
#define pii pair<ll, ll>
using namespace std;
const int N = 1e5 + 10;
const ll oo = 6e9;
int n, m;
ll a[N], v[N], S;
struct node {
    ll sum, pre;
    node(ll sum = 0, ll pre = -oo) : sum(sum), pre(pre) {}
	friend node operator * (const node a, const node b) {
		return node(a.sum + b.sum, max(a.pre, a.sum + b.pre));
	}
	void operator *= (const node b){
		pre=max(pre,sum+b.pre);
		sum+=b.sum;
	}
	friend node operator ^ (node a, ll b) {
	//	node res;
	//	for(; b; b>>=1,a*=a) if(b & 1) res*=a;
	//	return res;
		if(!b) return node();
		if(a.sum>=0) return node(a.sum*b,a.pre+a.sum*(b-1));
		return node(a.sum*b,a.pre);
	}
};
node exgcd(ll a, ll b, ll c, ll n, node U, node R) {
    b = (b % c + c) % c;
	if(a >= c) return exgcd(a % c, b, c, n, U, (U ^ a / c) * R);
	ll m = ((ll)a * n + b) / c;
	if(m == 0) return R ^ n;
	swap(U, R);
	return (U ^ (c - b - 1) / a) * R * exgcd(c, c - b - 1, a, m - 1, U, R) * (U ^ (n - ((ll) m * c - b - 1) / a));
}
ll calc(ll a, ll x, ll c, ll now) {
    node U(-c, -oo), R(x, x), S(now, now);
    S = S * exgcd(x, now, c, a, U, R);
    return S.pre;
}
int check(int x) {
    ll now = 0, sum = 0;
    ll lim = m * S;
    FOR(i, 1, n - 1) {
        sum += (v[i] + a[i]) * x - S;
        if(sum >= 0 && sum > lim) return 0;
    }
    sum += (S - 1) * (n - 1);
    FOR(i, 1, n - 1) {
        now += v[i] * x - 1;
        now %= S;
        ll mx = calc(a[i], x, S, now);
        sum -= mx;
        now = (now + a[i] * x + S - mx) % S;
    }
    assert(sum % S == 0);
    if(x + sum / S <= m) return 1;
    return 0;
}
int main() {
    ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    FOR(i, 0, n - 1) cin >> v[i];
    FOR(i, 0, n - 1) cin >> a[i];
    S = v[0] + a[0], a[0] = 0;
    S += a[n - 1], a[n - 1] = 0;
    int l = 1, r = m, x = 0;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(check(mid)) x = mid, l = mid + 1;
        else r = mid - 1;
    }
    cout << x << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3448kb

input:

6 2
4 2 2 2 4 6
4 6
6 4

output:

1

result:

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