QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#285666 | #5000. Balanced Seesaw Array | Zeoy | RE | 3ms | 34916kb | C++20 | 3.8kb | 2023-12-16 21:17:48 | 2023-12-16 21:17:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 1e5 + 10, M = 4e5 + 10;
using i64 = __int128;
int n, q, a[N];
struct info {
i64 sum2, sum, len;
info(i64 sum2_ = 0, i64 sum_ = 0, i64 len_ = 0) : sum2(sum2_), sum(sum_), len(len_) {}
friend info operator+(const info &a, const info &b) {
info c;
c.len = a.len + b.len;
c.sum = a.sum + b.sum;
c.sum2 = a.sum2 + b.sum2 + a.len * b.sum2;
return c;
}
};
struct SEG {
info val;
i64 lazy1, lazy2; // lazy1 : 区间加标记, lazy2 : 区间覆盖标记
} seg[N << 2];
void up(int id) { seg[id].val = seg[lson].val + seg[rson].val; }
void settag1(int id, i64 tag) {
auto [sum2, sum, len] = seg[id].val;
seg[id].val.sum2 += (1 + len) * len / 2 * tag;
seg[id].val.sum += len * tag;
seg[id].lazy1 += tag;
}
void settag2(int id, i64 tag) {
auto [sum2, sum, len] = seg[id].val;
seg[id].val.sum2 = (1 + len) * len / 2 * tag;
seg[id].val.sum = len * tag;
seg[id].lazy2 = tag;
seg[id].lazy1 = 0;
}
void down(int id) {
if (seg[id].lazy2 != -inf) {
settag2(lson, seg[id].lazy2);
settag2(rson, seg[id].lazy2);
seg[id].lazy2 = -inf;
}
if (seg[id].lazy1 != 0) {
settag1(lson, seg[id].lazy1);
settag1(rson, seg[id].lazy1);
seg[id].lazy1 = 0;
}
}
void build(int id, int l, int r) {
seg[id].lazy1 = 0, seg[id].lazy2 = -inf;
if (l == r) {
seg[id].val = info(a[l], a[l], 1);
return;
}
int mid = l + r >> 1;
build(lson, l, mid);
build(rson, mid + 1, r);
up(id);
}
void modify1(int id, int l, int r, int ql, int qr, i64 v) {
if (ql <= l && r <= qr) {
settag1(id, v);
return;
}
down(id);
int mid = l + r >> 1;
if (qr <= mid) modify1(lson, l, mid, ql, qr, v);
else if (ql > mid) modify1(rson, mid + 1, r, ql, qr, v);
else modify1(lson, l, mid, ql, qr, v), modify1(rson, mid + 1, r, ql, qr, v);
up(id);
}
void modify2(int id, int l, int r, int ql, int qr, i64 v) {
if (ql <= l && r <= qr) {
settag2(id, v);
return;
}
down(id);
int mid = l + r >> 1;
if (qr <= mid) modify2(lson, l, mid, ql, qr, v);
else if (ql > mid) modify2(rson, mid + 1, r, ql, qr, v);
else modify2(lson, l, mid, ql, qr, v), modify2(rson, mid + 1, r, ql, qr, v);
up(id);
}
info query(int id, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return seg[id].val;
down(id);
int mid = l + r >> 1;
if (qr <= mid) return query(lson, l, mid, ql, qr);
else if (ql > mid) return query(rson, mid + 1, r, ql, qr);
else return query(lson, l, mid, ql, qr) + query(rson, mid + 1, r, ql, qr);
}
void solve() {
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> a[i];
build(1, 1, n);
while (q--) {
int op, l, r, x;
cin >> op >> l >> r;
if (op == 1) {
cin >> x;
modify1(1, 1, n, l, r, x);
} else if (op == 2) {
cin >> x;
modify2(1, 1, n, l, r, x);
} else {
auto ans = query(1, 1, n, l, r);
// cerr << ans.sum2 << " " << ans.sum << endl;
cout << (ans.sum2 % ans.sum == 0 ? "Yes" : "No") << endl;
}
}
}
signed main(void) {
Zeoy;
int Test = 1;
// cin >> Test;
while (Test--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 34916kb
input:
3 6 1 2 3 3 1 1 3 1 3 1 1 1 2 3 1 3 2 2 2 0 3 2 3
output:
Yes No Yes Yes
result:
ok 4 lines
Test #2:
score: -100
Runtime Error
input:
100000 451163 -18 609 -793 393 375 313 -55 -892 -446 928 -207 -390 729 -383 27 318 -400 31 -661 202 -978 212 238 -368 351 -613 -23 400 809 1000 -431 -174 -103 886 73 -150 25 820 -689 972 777 794 -36 -231 -966 632 -418 -288 -476 725 -713 -379 896 -19 -883 338 -797 937 -557 -809 -241 -539 704 44 576 -...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...