QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187249 | #3850. DJ Darko | realIyxiang# | WA | 451ms | 23248kb | C++14 | 3.1kb | 2023-09-24 15:45:53 | 2023-09-24 15:45:54 |
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.upper_bound((node){p, n + 1}); --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));
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) st[++tp] = (*it);
// cout << "upd : \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 << ' ' << a[u.l] + FT :: qry(u.l) << '\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);
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 = -1e9, vr = 1e9;
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: 451ms
memory: 23248kb
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 1000000000 1000000000 467651597 1000000000 1000000000 1000000000 1000000000 124416557 1000000000 -893932302 -299565953 487025138 -299565953 -299565953 -299565953 -299565953 -299565953 -299565953 -299565953 -299565953 -551538129 -551538129 -551538129 -1000000000 837993047 267673497 26767349...
result:
wrong answer 2nd lines differ - expected: '1749348519', found: '1000000000'