QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#825199 | #9774. Same Sum | ucup-team045# | WA | 0ms | 6304kb | C++20 | 8.1kb | 2024-12-21 17:41:57 | 2024-12-21 17:42:07 |
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 17:41:57]
- 提交
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<array>
#include<stdint.h>
using namespace std;
using LL = long long;
template<const int T>
struct ModInt {
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
ModInt(long long x) : x(int(x % mod)) {}
int val() { return x; }
ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
bool operator == (const ModInt &a) const { return x == a.x; };
bool operator != (const ModInt &a) const { return x != a.x; };
void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
void operator /= (const ModInt &a) { *this = *this / a; }
friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while(n){
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const {
int a = x, b = mod, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0) u += mod;
return u;
}
};
using mint = ModInt<1004535809>;
const int M = 3;
mint C[M + 1][M + 1];
#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<functional>
using namespace std;
struct Info{
array<mint, M + 1> hsh;
Info(array<mint, M + 1> hsh = {}) : hsh(hsh) {}
};
using Tag = mint;
Info operator+(const Info &a, const Info &b){
Info ret;
for(int i = 0; i <= M; i++){
ret.hsh[i] = a.hsh[i] + b.hsh[i];
}
return ret;
}
mint pows[M + 1];
void apply(Info &x, Tag &a, Tag f){
if (f == 0) return;
pows[0] = 1;
for(int i = 1; i <= M; i++) pows[i] = pows[i - 1] * f;
for(int i = M; i >= 0; i--){
for(int j = 0; j < i; j++){
x.hsh[i] += C[i][j] * x.hsh[j] * pows[i - j];
}
}
a += f;
}
template<class Info, class Tag>
struct LazySegmentTree{
int n;
vector<Info> info;
vector<Tag> tag;
LazySegmentTree() {}
LazySegmentTree(int n, Info _init = Info()){
init(vector<Info>(n, _init));
}
LazySegmentTree(const vector<Info> &_init){
init(_init);
}
void init(const vector<Info> &_init){
n = (int)_init.size();
info.assign((n << 2) + 1, Info());
tag.assign((n << 2) + 1, Tag());
function<void(int, int, int)> build = [&](int p, int l, int r){
if (l == r){
info[p] = _init[l - 1];
return;
}
int m = (l + r) / 2;
build(2 * p, l, m);
build(2 * p + 1, m + 1, r);
pull(p);
};
build(1, 1, n);
}
void pull(int p){
info[p] = info[2 * p] + info[2 * p + 1];
}
void apply(int p, const Tag &v){
::apply(info[p], tag[p], v);
}
void push(int p){
apply(2 * p, tag[p]);
apply(2 * p + 1, tag[p]);
tag[p] = Tag();
}
void modify(int p, int l, int r, int x, const Info &v){
if (l == r){
info[p] = v;
return;
}
int m = (l + r) / 2;
push(p);
if (x <= m){
modify(2 * p, l, m, x, v);
}
else{
modify(2 * p + 1, m + 1, r, x, v);
}
pull(p);
}
void modify(int p, const Info &v){
modify(1, 1, n, p, v);
}
Info query(int p, int l, int r, int x, int y){
if (l > y || r < x){
return Info();
}
if (l >= x && r <= y){
return info[p];
}
int m = (l + r) / 2;
push(p);
return query(2 * p, l, m, x, y) + query(2 * p + 1, m + 1, r, x, y);
}
Info query(int l, int r){
return query(1, 1, n, l, r);
}
mint query_sum(int p, int l, int r, int x, int y){
if (l > y || r < x){
return 0;
}
if (l >= x && r <= y){
return info[p].hsh[1];
}
int m = (l + r) / 2;
push(p);
return query_sum(2 * p, l, m, x, y) + query_sum(2 * p + 1, m + 1, r, x, y);
}
mint query_sum(int l, int r){
return query_sum(1, 1, n, l, r);
}
void modify(int p, int l, int r, int x, int y, const Tag &v){
if (l > y || r < x){
return;
}
if (l >= x && r <= y){
apply(p, v);
return;
}
int m = (l + r) / 2;
push(p);
modify(2 * p, l, m, x, y, v);
modify(2 * p + 1, m + 1, r, x, y, v);
pull(p);
}
void modify(int l, int r, const Tag &v){
return modify(1, 1, n, l, r, v);
}
};
const int maxn = 2e5 + 5, mod = 1e9 + 9;;
mint inv[maxn];
void init(){
inv[1] = 1;
for(int i = 2; i < maxn; i++)
inv[i] = mint(mod - mod / i) * inv[mod % i];
}
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2) ? EOF: *p1++)
template<typename T>
void read(T &x){
x = 0;
T w = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
x *= w;
}
template<typename T, typename... Args>
void read(T &first, Args& ... args) {
read(first);
read(args...);
}
template<typename T>
void write(T x){
if (x < 0) {putchar('-'); x = -x;}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template<typename T, typename... Args>
void write(T first, Args ... args){
write(first);
write(args...);
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
init();
for(int i = 0; i <= M; i++){
for(int j = 0; j <= i; j++){
if (!j) C[i][j] = 1;
else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
int n, q;
read(n, q);
vector<Info> init(n);
for(int i = 0; i < n; i++){
int x;
read(x);
init[i].hsh[0] = 1;
for(int j = 1; j <= M; j++){
init[i].hsh[j] = init[i].hsh[j - 1] * x;
}
}
LazySegmentTree<Info, Tag> seg(init);
while(q--){
int op;
read(op);
if (op == 1){
int l, r, v;
read(l, r, v);
seg.modify(l, r, v);
}
else{
int l, r;
read(l, r);
mint ave = seg.query_sum(l, r) * inv[r - l + 1];
seg.modify(l, r, 0 - ave);
auto hsh = seg.query(l, r).hsh;
bool ok = true;
for(int i = 1; i <= M; i += 2){
if (hsh[i].x != 0){
ok = false;
break;
}
}
puts(ok ? "YES" : "NO");
seg.modify(l, r, ave);
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 6304kb
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:
NO NO NO
result:
wrong answer expected YES, found NO [1st token]