QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508218#1140. Distributing Candieszhoukangyang#0 261ms81328kbC++142.5kb2024-08-07 09:49:052024-08-07 09:49:05

Judging History

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

  • [2024-08-07 09:49:05]
  • 评测
  • 测评结果:0
  • 用时:261ms
  • 内存:81328kb
  • [2024-08-07 09:49:05]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int > 
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
#define pb emplace_back
#define i128 __int128
using namespace std;
const int N = 1e6 + 7, mod = 1e9 + 7;

int n;
struct tag {
	ll inc;
	ll l, r;
	tag() {
		inc = 0;
		l = 0;
		r = mod;
	}
	ll calc(ll w) {
		return min(max(w + inc, l), r);
	}
};
tag operator + (tag l, tag r) {
	tag o;
	o.inc = l.inc + r.inc;
	o.l = r.calc(l.l);
	o.r = r.calc(l.r);
	return o;
}
vi ins[N], del[N];
int f[N];
ll sum[N], pmx[N], pmn[N];
void modify(int x, int L, int R, int p, int w) {
	if(L == R) {
		sum[x] = w;
		pmx[x] = max(w, 0);
		pmn[x] = min(w, 0);
		return;
	}
	int mid = (L + R) >> 1;
	p <= mid ? modify(x * 2, L, mid, p, w) : modify(x * 2 + 1, mid + 1, R, p, w);
	sum[x] = sum[x * 2] + sum[x * 2 + 1];
	pmx[x] = max(pmx[x * 2], sum[x] + pmx[x * 2 + 1]);
	pmn[x] = min(pmn[x * 2], sum[x] + pmn[x * 2 + 1]);
}
ll s, mx, mn, ans;
int cap;
void query(int x, int L, int R) {
	if(mx - mn >= cap) return;
	if(max(mx, s + pmx[x]) - min(mn, s + pmn[x]) < cap) {
		mx = max(mx, s + pmx[x]);
		mn = min(mn, s + pmn[x]);
		s += sum[x];
		return;
	}
	if(L == R) {
		mx = max(mx, s + pmx[x]);
		mn = min(mn, s + pmn[x]);
		s += sum[x];
		ans = sum[x] > 0 ? cap + mn : mx;
		return;
	}
	int mid = (L + R) >> 1;
	query(x * 2, L, mid);
	query(x * 2 + 1, mid + 1, R);

}
vi distribute_candies(vi c, vi l, vi r, vi v) {
	n = sz(c);
	reverse(l.begin(), l.end());
	reverse(r.begin(), r.end());
	reverse(v.begin(), v.end());
	L(i, 0, sz(l) - 1) 
		ins[l[i]].pb(i), del[r[i]].pb(i);
	vi ns(n);
	L(p, 0, sz(c) - 1) {
		for(auto&u : ins[p]) {
			modify(1, 0, sz(l) - 1, u, v[u]);
		}
		s = 0, mx = 0, mn = 0, cap = c[p], ans = -1;
		query(1, 0, sz(l) - 1);
		// L(i, 0, sz(l) - 1) {
		// 	if(l[i] <= p && p <= r[i]) {
		// 		x += v[i];
		// 		mn = min(mn, x);
		// 		mx = max(mx, x);
		// 		if(mx - mn >= c[p]) {
		// 			ans = v[i] > 0 ? c[p] + mn : mx;
		// 			break;
		// 		}
		// 	}
		// }
		if(ans == -1) ans = mx;
		ns[p] = ans;
		for(auto&u : del[p]) {
			modify(1, 0, sz(l) - 1, u, 0);
		}
	}
	return ns;
}

// int main() {
//     auto P = distribute_candies(vi{10, 15, 13}, vi{0, 0}, vi{2, 1}, vi{20, -11});
// 	for(auto&u : P) cout << u << endl;
// 	return 0;
// }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 56396kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
8
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
8
0 7 1
0 7 1
0 7 300000000
0 7 994967293
0 7 1
0 7 1000000000
0 7 1000000000
0 7 1000000000

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

result:

ok 3 lines

Test #2:

score: 0
Wrong Answer
time: 8ms
memory: 56064kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
283 43634 101056 10340 6009 5133 30 2 3677888 210
10
1 8 26416
2 7 -51219
2 4 17793
3 7 75426
3 7 22307
1 1 60258
3 7 -29824
0 8 24839
2 8 -60304
0 1 -26411

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 17223 121 0 0 0 0 0 70199 0

result:

wrong answer 3rd lines differ - expected: '0 17223 0 0 0 0 0 0 0 0', found: '0 17223 121 0 0 0 0 0 70199 0'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 261ms
memory: 81328kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
510975 510975 37843 28 53693 1443318 103 297546 1096200 2432198 26 1 6172 3291760 431 4288256 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 7597133 55362 253 2363145 8146456 1103 19622 594 7867 1 4299 28130 48 4685884 12 431 123 10096182 ...

result:

wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '510975 510975 37843 28 53693 1...697 9 1756 1598274 1314129 1629'

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 9ms
memory: 51972kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
1000
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 3rd lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 11ms
memory: 56396kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
11 440 51 41 11 1 3 108 148 14
10
0 9 60
0 9 -9
0 9 -30
0 9 41
0 9 82
0 9 69
0 9 -79
0 9 -39
0 9 72
0 9 41

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
11 319 51 41 11 1 3 108 143 14

result:

wrong answer 3rd lines differ - expected: '11 208 51 41 11 1 3 108 143 14', found: '11 319 51 41 11 1 3 108 143 14'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%