QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#600376 | #5000. Balanced Seesaw Array | Yshanqian | WA | 225ms | 20984kb | C++20 | 3.4kb | 2024-09-29 16:09:08 | 2024-09-29 16:09:09 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<__int128, __int128> pii;
const int N = 2e5 + 10, inf = 1e18;
struct node
{
int l, r;
__int128 sum1, sum2;
int lazy1, lazy2;
} tr[N << 2];
int a[N];
void pushup(int u)
{
tr[u].sum1 = tr[u << 1].sum1 + tr[u << 1 | 1].sum1;
tr[u].sum2 = tr[u << 1].sum2 + tr[u << 1 | 1].sum2;
}
void build(int u, int l, int r)
{
tr[u] = {l, r, 0, 0, 0, 0};
if (l == r)
{
tr[u].sum1 = a[l] * l;
tr[u].sum2 = a[l];
return;
}
int mid = (l + r) >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void change(int u, int op, int x)
{
if (op == 1)
{
tr[u].sum1 += x * (tr[u].r * (tr[u].r + 1) / 2 - tr[u].l * (tr[u].l - 1) / 2);
tr[u].sum2 += (tr[u].r - tr[u].l + 1) * x;
tr[u].lazy2 = 0;
tr[u].lazy1 += x;
}
else
{
tr[u].sum1 = x * (tr[u].r * (tr[u].r + 1) / 2 - tr[u].l * (tr[u].l - 1) / 2);
tr[u].sum2 = (tr[u].r - tr[u].l + 1) * x;
tr[u].lazy1 = 0;
tr[u].lazy2 = x;
}
}
void pushdown(int u)
{
if (tr[u].lazy1)
{
change(u << 1, 1, tr[u].lazy1);
change(u << 1 | 1, 1, tr[u].lazy1);
tr[u].lazy1 = 0;
}
if (tr[u].lazy2)
{
change(u << 1, 2, tr[u].lazy2);
change(u << 1 | 1, 2, tr[u].lazy2);
tr[u].lazy2 = 0;
}
}
void modify(int u, int l, int r, int op, int x)
{
if (tr[u].l >= l && tr[u].r <= r)
{
change(u, op, x);
return;
}
int mid = (tr[u].l + tr[u].r) >> 1;
pushdown(u);
if (l <= mid)
modify(u << 1, l, r, op, x);
if (r > mid)
modify(u << 1 | 1, l, r, op, x);
pushup(u);
}
pii query(int u, int l, int r)
{
if (tr[u].l >= l && tr[u].r <= r)
{
return {tr[u].sum1, tr[u].sum2};
}
int mid = (tr[u].l + tr[u].r) >> 1;
pushdown(u);
int res1 = 0, res2 = 0;
if (l <= mid)
{
pii xx = query(u << 1, l, r);
res1 += xx.first;
res2 += xx.second;
}
if (r > mid)
{
pii xx = query(u << 1 | 1, l, r);
res1 += xx.first;
res2 += xx.second;
}
return {res1, res2};
}
void solve()
{
int n, q;
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 || op == 2)
{
cin >> x;
modify(1, l, r, op, x);
}
else
{
auto [x, y] = query(1, l, r);
__int128 res1 = x - (l - 1) * y;
__int128 res2 = y;
if (res2 == 0)
{
if (res1 == res2)
cout << "Yes\n";
else
cout << "No\n";
}
else
{
__int128 k = res1 / res2;
if (res1 == res2 * k && k >= 1 && k <= r - l + 1)
cout << "Yes\n";
else
cout << "No\n";
}
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5664kb
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
Wrong Answer
time: 225ms
memory: 20984kb
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 Yes No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No Yes No No No No No No No Yes No No No No No Yes No No No No No No No No No No No No No No No No No No No No No Yes No Yes No No No No No No No No No No No No No No No No No No No No No No No No Yes No N...
result:
wrong answer 9th lines differ - expected: 'Yes', found: 'No'