QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187301 | #3850. DJ Darko | realIyxiang# | WA | 696ms | 23916kb | C++14 | 3.2kb | 2023-09-24 16:11:47 | 2023-09-24 16:11:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 2e5 + 5;
struct node {
int l, r;
bool operator < (const node &x) const {
return l == x.l ? r < x.r : l < x.l;
}
} u, st[N];
int n, q, l, r, x, op, tp, a[N], b[N];
set <node> S;
namespace FT {
int c[N];
void add (int p, int k) {
for (int i = p; i <= n; i += (i & (-i)))
c[i] += k;
}
void upd (int l, int r, int k) {
add(l, k), add(r + 1, -k);
}
int qry (int p) {
int ans = 0;
for (int i = p; i; i -= (i & (-i)))
ans += c[i];
return ans;
}
}
void split (int p) {
if(p > n) return ;
auto it = S.lower_bound((node){p + 1, 0}); --it;
node u = *it;
S.erase(u);
if(u.l != p) S.insert((node){u.l, p - 1});
S.insert((node){p, u.r});
int val = FT :: qry(u.l);
FT :: upd(p, p, -FT :: qry(p));
FT :: upd(p, p, val);
a[p] = a[u.l];
}
void update (int l, int r, int x) {
a[l] = x, FT :: upd(l, l, -FT :: qry(l));
auto itl = S.lower_bound((node){l, 0});
auto itr = S.lower_bound((node){r + 1, 0});
for (auto it = itl; it != itr; ++it) st[++tp] = (*it);
// cout << "upd : " << l << ' ' << r << ' ' << x << ' ' << a[l] + FT :: qry(l) << '\n';
for ( ; tp; --tp) S.erase(st[tp])/*, cout << st[tp].l << ' ' << st[tp].r << '\n'*/;
S.insert((node){l, r});
}
bool check (int v) {
int s = 0, cur = 0; node u;
auto itl = S.lower_bound((node){l, 0});
auto itr = S.lower_bound((node){r + 1, 0});
for (auto it = itl; it != itr; ++it) {
u = *it;
s += b[u.l] * (u.r - u.l + 1);
// cerr << "! : " << u.l << ' ' << u.r << ' ' << a[u.l] << '\n';
if(a[u.l] <= v) cur += b[u.l] * (u.r - u.l + 1)/*, cerr << "! : " << a[u.l] << ' ' << u.l << ' ' << u.r << '\n'*/;
}
// cerr << v << ' ' << s << ' ' << cur << '\n';
return cur >= s / 2;
}
void print () {
cout << "print : " << '\n';
for (auto it : S) {
u = it;
cout << u.l << ' ' << u.r << ' ' << a[u.l] + FT :: qry(u.l) << '\n';
}
rep(i, 1, n) cout << FT :: qry(i) << ' '; cout << '\n';
}
signed main () {
scanf("%lld%lld", &n, &q);
rep(i, 1, n) scanf("%lld", &a[i]);
rep(i, 1, n) scanf("%lld", &b[i]);
rep(i, 1, n) S.insert((node){i, i});
while (q--) {
scanf("%lld%lld%lld", &op, &l, &r);
if(op == 1) {
scanf("%lld", &x);
split(l), split(r + 1);
FT :: upd(l, r, x);
} else {
split(l), split(r + 1);
auto itl = S.lower_bound((node){l, 0});
auto itr = S.lower_bound((node){r + 1, 0});
for (auto it = itl; it != itr; ++it) {
u = *it;
a[u.l] += FT :: qry(u.l), FT :: upd(u.l, u.l, -FT :: qry(u.l));
}
int vl = -1e16, vr = 1e16;
while (vl < vr) {
int Mid = vl + vr;
if(Mid < 0) Mid = (Mid - 1) / 2;
else Mid = Mid / 2;
// cerr << vl << ' ' << vr << ' ' << Mid << ' ' << check(Mid) << '\n';
if(check(Mid)) vr = Mid;
else vl = Mid + 1;
}
update(l, r, vl);
printf("%lld\n", vl);
}
// print();
// cerr << "ok : " << q << '\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 696ms
memory: 23916kb
input:
200000 200000 185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...
output:
462406736 1749348519 1749348519 467651597 1749348519 1749348519 1749348519 1749348519 873765076 1749348519 -893932302 449782566 1749348519 1207320940 449782566 1207320940 1207320940 1207320940 1207320940 1207320940 449782566 955348764 955348764 955348764 204344119 1040110566 1040110566 1040110566 10...
result:
wrong answer 5th lines differ - expected: '874061694', found: '1749348519'