QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#824522 | #9774. Same Sum | ucup-team4474# | WA | 1218ms | 18584kb | C++20 | 5.7kb | 2024-12-21 14:31:27 | 2024-12-21 14:31:28 |
Judging History
你现在查看的是最新测评结果
- [2025-01-11 11:59:18]
- hack成功,自动添加数据
- (/hack/1443)
- [2024-12-23 17:02:06]
- hack成功,自动添加数据
- (/hack/1310)
- [2024-12-23 16:48:26]
- hack成功,自动添加数据
- (/hack/1309)
- [2024-12-23 16:33:45]
- hack成功,自动添加数据
- (/hack/1308)
- [2024-12-23 16:23:53]
- hack成功,自动添加数据
- (/hack/1307)
- [2024-12-23 16:13:08]
- hack成功,自动添加数据
- (/hack/1306)
- [2024-12-23 15:54:42]
- hack成功,自动添加数据
- (/hack/1305)
- [2024-12-23 14:58:39]
- hack成功,自动添加数据
- (/hack/1304)
- [2024-12-23 09:58:11]
- hack成功,自动添加数据
- (/hack/1302)
- [2024-12-23 09:47:22]
- hack成功,自动添加数据
- (/hack/1301)
- [2024-12-23 09:41:23]
- hack成功,自动添加数据
- (/hack/1300)
- [2024-12-23 09:26:32]
- hack成功,自动添加数据
- (/hack/1299)
- [2024-12-23 09:19:58]
- hack成功,自动添加数据
- (/hack/1298)
- [2024-12-23 09:13:29]
- hack成功,自动添加数据
- (/hack/1297)
- [2024-12-22 18:52:18]
- hack成功,自动添加数据
- (/hack/1296)
- [2024-12-22 18:13:14]
- hack成功,自动添加数据
- (/hack/1294)
- [2024-12-21 14:31:27]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using i128 = __int128_t;
bool Memory_begin;
template <int mod>
unsigned int down(unsigned int x)
{
return x >= mod ? x - mod : x;
}
template <int mod>
struct Modint
{
unsigned int x;
Modint() = default;
Modint(unsigned int x) : x(x) {}
friend istream &operator>>(istream &in, Modint &a) { return in >> a.x; }
friend ostream &operator<<(ostream &out, Modint a) { return out << a.x; }
friend Modint operator+(Modint a, Modint b) { return down<mod>(a.x + b.x); }
friend Modint operator-(Modint a, Modint b) { return down<mod>(a.x - b.x + mod); }
friend Modint operator*(Modint a, Modint b) { return 1ULL * a.x * b.x % mod; }
friend Modint operator/(Modint a, Modint b) { return a * ~b; }
friend Modint operator^(Modint a, i64 b)
{
Modint ans = 1;
for (; b; b >>= 1, a *= a)
if (b & 1)
ans *= a;
return ans;
}
friend Modint operator~(Modint a) { return a ^ (mod - 2); }
friend Modint operator-(Modint a) { return down<mod>(mod - a.x); }
friend Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
friend Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
friend Modint &operator*=(Modint &a, Modint b) { return a = a * b; }
friend Modint &operator/=(Modint &a, Modint b) { return a = a / b; }
friend Modint &operator^=(Modint &a, i64 b) { return a = a ^ b; }
friend Modint &operator++(Modint &a) { return a += 1; }
friend Modint operator++(Modint &a, int)
{
Modint x = a;
a += 1;
return x;
}
friend Modint &operator--(Modint &a) { return a -= 1; }
friend Modint operator--(Modint &a, int)
{
Modint x = a;
a -= 1;
return x;
}
friend bool operator==(Modint a, Modint b) { return a.x == b.x; }
friend bool operator!=(Modint a, Modint b) { return !(a == b); }
};
const int mod = 998244353;
typedef Modint<mod> mint;
const mint base = 91, e = 1;
const int N = 2e5 + 5;
int n, q, a[N];
struct node
{
mint tag;
mint sum1, sum2;
int tag0;
i64 sum0;
} st[N << 2];
void build(int cur, int l, int r)
{
st[cur].tag = e;
if (l == r)
{
st[cur].sum0 = a[l];
st[cur].sum1 = base ^ a[l];
st[cur].sum2 = e / st[cur].sum1;
return;
}
int mid = l + r >> 1;
build(cur << 1, l, mid);
build(cur << 1 | 1, mid + 1, r);
st[cur].sum1 = st[cur << 1].sum1 + st[cur << 1 | 1].sum1;
st[cur].sum2 = st[cur << 1].sum2 + st[cur << 1 | 1].sum2;
st[cur].sum0 = st[cur << 1].sum0 + st[cur << 1 | 1].sum0;
}
void pushdown(int cur, int l, int mid, int r)
{
if (st[cur].tag == e)
return;
st[cur << 1].tag *= st[cur].tag;
st[cur << 1].sum1 *= st[cur].tag;
st[cur << 1].sum2 /= st[cur].tag;
st[cur << 1].tag0 += st[cur].tag0;
st[cur << 1].sum0 += 1ll * (mid - l + 1) * st[cur].tag0;
st[cur << 1 | 1].tag *= st[cur].tag;
st[cur << 1 | 1].sum1 *= st[cur].tag;
st[cur << 1 | 1].sum2 /= st[cur].tag;
st[cur << 1 | 1].tag0 += st[cur].tag0;
st[cur << 1 | 1].sum0 += 1ll * (r - mid) * st[cur].tag0;
st[cur].tag = e, st[cur].tag0 = 0;
}
void update(int cur, int l, int r, int a, int b, int x)
{
if (a <= l and r <= b)
{
st[cur].tag0 += x;
st[cur].sum0 += 1ll * x * (r - l + 1);
mint tmp = base ^ x;
st[cur].tag *= tmp;
st[cur].sum1 *= tmp;
st[cur].sum2 /= tmp;
return;
}
int mid = l + r >> 1;
pushdown(cur, l, mid, r);
if (a <= mid)
update(cur << 1, l, mid, a, b, x);
if (b > mid)
update(cur << 1 | 1, mid + 1, r, a, b, x);
st[cur].sum1 = st[cur << 1].sum1 + st[cur << 1 | 1].sum1;
st[cur].sum2 = st[cur << 1].sum2 + st[cur << 1 | 1].sum2;
st[cur].sum0 = st[cur << 1].sum0 + st[cur << 1 | 1].sum0;
}
pair<mint, mint> query(int cur, int l, int r, int a, int b)
{
if (a <= l and r <= b)
return {st[cur].sum1, st[cur].sum2};
if (a > r or b < l)
return {e, e};
int mid = l + r >> 1;
pushdown(cur, l, mid, r);
auto lft = query(cur << 1, l, mid, a, b);
auto rht = query(cur << 1 | 1, mid + 1, r, a, b);
return {lft.first + rht.first, lft.second + rht.second};
}
i64 query1(int cur, int l, int r, int a, int b)
{
if (a <= l and r <= b)
return st[cur].sum0;
if (a > r or b < l)
return 0;
int mid = l + r >> 1;
pushdown(cur, l, mid, r);
return query1(cur << 1, l, mid, a, b) + query1(cur << 1 | 1, mid + 1, r, a, b);
}
bool Memory_end;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cerr << (&Memory_end - &Memory_begin) / 1048576.0 << "MB" << '\n';
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> a[i];
build(1, 1, n);
while (q--)
{
int opt;
cin >> opt;
if (opt == 1)
{
int l, r, x;
cin >> l >> r >> x;
update(1, 1, n, l, r, x);
}
else
{
int l, r;
cin >> l >> r;
i64 s = query1(1, 1, n, l, r) * 2;
bool ans = false;
if (s % (r - l + 1) == 0)
{
s /= r - l + 1;
auto tmp = query(1, 1, n, l, r);
tmp.second *= base ^ s;
if (tmp.first == tmp.second)
ans = true;
}
if (ans)
cout << "YES\n";
else
cout << "NO\n";
}
}
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
8 4 1 2 3 4 5 6 7 8 2 1 8 1 1 4 4 2 1 6 2 1 8
output:
YES NO YES
result:
ok 3 token(s): yes count is 2, no count is 1
Test #2:
score: -100
Wrong Answer
time: 1218ms
memory: 18584kb
input:
200000 200000 0 0 0 1 1 0 2 1 1 2 0 1 0 0 0 2 1 0 1 2 2 1 2 1 2 0 0 2 1 2 1 0 0 2 0 2 1 1 1 2 0 0 0 0 2 0 1 0 0 2 2 1 1 0 0 2 1 0 2 0 2 1 2 1 0 1 2 1 0 1 2 1 2 1 0 1 2 0 1 0 1 1 0 2 1 2 0 2 2 1 1 2 1 2 2 0 0 1 2 0 0 2 2 0 1 2 2 0 0 1 2 1 2 0 2 0 0 2 0 2 1 0 1 1 1 1 2 1 2 0 1 2 1 0 2 1 0 1 1 2 2 0 1 ...
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 ...
result:
wrong answer expected YES, found NO [464th token]