QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#644282 | #9302. Caesar Cipher | castc | WA | 1335ms | 87276kb | C++20 | 5.3kb | 2024-10-16 12:44:26 | 2024-10-21 09:40:14 |
Judging History
你现在查看的是最新测评结果
- [2024-11-04 17:10:09]
- hack成功,自动添加数据
- (/hack/1110)
- [2024-10-21 09:47:48]
- hack成功,自动添加数据
- (/hack/1022)
- [2024-10-21 09:39:50]
- hack成功,自动添加数据
- (/hack/1021)
- [2024-10-21 09:31:34]
- hack成功,自动添加数据
- (/hack/1020)
- [2024-10-16 12:44:26]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define int long long
template<class Info, class Tag>
struct LazySegmentTree {
const int n;
vector<Info> info;
vector<Tag> tag;
LazySegmentTree(int n) : n(n), info(4 << __lg(n)), tag(4 << __lg(n)) {}
LazySegmentTree(vector<Info> init) : LazySegmentTree(init.size()) {
function<void(int, int, int)> build = [&](int p, int l, int r) {
if (l == r) {
info[p] = init[l];
return;
}
int m = (l + r) / 2;
build(2 * p, l, m);
build(2 * p + 1, m + 1, r);
pull(p);
};
build(1, 0, n - 1);
}
void pull(int p) {
info[p] = info[2 * p] + info[2 * p + 1];
}
void apply(int p, const Tag &v) {
info[p].apply(v);
tag[p].apply(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, 0, n - 1, p, v);
}
Info rangeQuery(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 rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m + 1, r, x, y);
}
Info rangeQuery(int l, int r) {
if(l > r) return Info();
return rangeQuery(1, 0, n - 1, l, r);
}
void rangeApply(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);
rangeApply(2 * p, l, m, x, y, v);
rangeApply(2 * p + 1, m + 1, r, x, y, v);
pull(p);
}
void rangeApply(int l, int r, const Tag &v) {
return rangeApply(1, 0, n - 1, l, r, v);
}
void half(int p, int l, int r) {
if (info[p].act == 0) {
return;
}
if ((info[p].min + 1) / 2 == (info[p].max + 1) / 2) {
apply(p, {-(info[p].min + 1) / 2});
return;
}
int m = (l + r) / 2;
push(p);
half(2 * p, l, m);
half(2 * p + 1, m + 1, r);
pull(p);
}
void half() {
half(1, 0, n - 1);
}
};
const int mod = 1247493647;
const int P = 65536;
const int N = 5e5 + 9;
int pw[N];
struct Tag {
ll add = 0;
void apply(Tag t) {
add += t.add;
}
};
struct Info {
int ans = 0, add = 0, g = 0, sum = 0;
void apply(Tag t) {
ans += t.add * add % mod;
sum += t.add * g;
}
};
Info operator+(Info a, Info b) {
Info c;
if(a.add == 0) return b;
if(b.add == 0) return a;
c.sum = (a.sum + b.sum) % P;
c.ans = (a.ans * pw[b.g] + b.ans) % mod;
c.add = (a.add * pw[b.g] + b.add) % mod;
c.g = a.g + b.g;
return c;
}
void solve() {
pw[0] = 1;
for(int i = 1; i < N; i++) {
pw[i] = pw[i - 1] * 131;
pw[i] %= mod;
}
int n, q;
cin >> n >> q;
vector<Info> init(n);
vector<int> a(n), b(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
init[i].add = 1;
init[i].g = 1;
}
for(int i = 0; i < n; i++) {
if(i == 0) b[i] = a[i];
else b[i] = a[i] - a[i - 1];
b[i] += P;
b[i] %= P;
init[i].sum = init[i].ans = b[i];
}
LazySegmentTree<Info, Tag> seg(init);
while(q--) {
int op;
cin >> op;
if(op == 1) {
int l, r;
cin >> l >> r;
l--;
auto p = seg.rangeQuery(l, l);
p.ans++;
p.ans %= P;
p.sum = p.ans;
seg.modify(l, p);
if(r < n) {
p = seg.rangeQuery(r, r);
p.ans--;
p.ans += P;
p.ans %= P;
p.sum = p.ans;
seg.modify(r, p);
}
} else {
int x, y, L;
cin >> x >> y >> L;
x--, y--;
int flag = seg.rangeQuery(x + 1, x + L - 1).ans;
flag -= seg.rangeQuery(y + 1, y + L - 1).ans;
if(flag != 0) {
cout << "no\n";
} else {
if(seg.rangeQuery(0, x).sum == seg.rangeQuery(0, y).sum) {
cout << "yes\n";
} else {
cout << "no\n";
}
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
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: 3ms
memory: 7496kb
input:
5 6 1 2 1 2 1 2 1 2 2 2 1 3 3 1 1 1 1 3 5 2 1 2 4 2 1 2 2
output:
no yes no yes
result:
ok 4 token(s): yes count is 2, no count is 2
Test #2:
score: 0
Accepted
time: 0ms
memory: 7520kb
input:
3 3 0 65535 65535 2 1 2 2 1 2 3 2 1 2 2
output:
no yes
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: 0
Accepted
time: 4ms
memory: 7852kb
input:
1000 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes ...
result:
ok 1000 token(s): yes count is 1000, no count is 0
Test #4:
score: 0
Accepted
time: 196ms
memory: 25124kb
input:
100000 100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes ...
result:
ok 100000 token(s): yes count is 100000, no count is 0
Test #5:
score: 0
Accepted
time: 1335ms
memory: 87192kb
input:
500000 500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes ...
result:
ok 500000 token(s): yes count is 500000, no count is 0
Test #6:
score: 0
Accepted
time: 1177ms
memory: 87200kb
input:
500000 500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes ...
result:
ok 500000 token(s): yes count is 500000, no count is 0
Test #7:
score: 0
Accepted
time: 1152ms
memory: 87276kb
input:
500000 500000 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 6553...
output:
yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes no no no yes yes yes yes yes yes yes yes yes yes yes yes yes no yes ...
result:
ok 500000 token(s): yes count is 449947, no count is 50053
Test #8:
score: 0
Accepted
time: 862ms
memory: 87164kb
input:
500000 500000 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 4999...
output:
yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes no yes yes yes yes yes yes yes yes yes yes yes yes yes no yes yes yes yes yes no yes yes yes yes yes yes yes yes yes no yes no yes y...
result:
ok 251941 token(s): yes count is 226844, no count is 25097
Test #9:
score: 0
Accepted
time: 751ms
memory: 87124kb
input:
500000 500000 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 ...
output:
no no no no no no no no yes no no yes no no no no no no no no no no yes yes no no yes no no yes no no no yes 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 yes no no yes no no no no no no no no no yes no no no no no no no no no no no yes yes no no no yes no no no no yes...
result:
ok 251981 token(s): yes count is 32353, no count is 219628
Test #10:
score: 0
Accepted
time: 861ms
memory: 87260kb
input:
500000 500000 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 6553...
output:
yes yes yes yes no no no yes yes yes yes yes yes yes yes yes yes yes yes yes yes no yes no yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes no yes yes yes yes yes yes no yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes yes no ...
result:
ok 251952 token(s): yes count is 227079, no count is 24873
Test #11:
score: 0
Accepted
time: 726ms
memory: 86944kb
input:
500000 500000 2 1 2 3 1 2 3 2 3 3 3 2 3 2 2 3 3 1 1 2 1 1 3 1 2 2 1 2 1 2 3 1 1 3 2 2 3 3 3 1 3 1 2 3 3 3 3 1 1 3 1 1 3 2 2 3 1 3 1 2 1 1 1 3 2 1 1 2 3 1 3 3 1 3 2 2 3 3 2 3 2 1 3 2 3 3 2 3 1 1 2 1 3 3 3 2 1 2 1 1 1 1 3 1 3 1 1 3 2 1 3 2 1 1 3 3 1 3 1 3 1 2 2 1 1 1 2 2 1 1 1 3 3 1 2 3 3 2 1 3 3 1 2 ...
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 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 no no no no no no no no no no no no no...
result:
ok 251970 token(s): yes count is 4568, no count is 247402
Test #12:
score: 0
Accepted
time: 20ms
memory: 70180kb
input:
282544 1 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1...
output:
no
result:
ok NO
Extra Test:
score: -3
Extra Test Failed : Wrong Answer on 15
time: 0ms
memory: 7696kb
input:
41 1 0 15 15 15 31 34 41 41 41 41 41 41 41 43 43 43 43 63 67 67 65469 0 0 4 24 24 24 24 26 26 26 26 26 26 26 33 36 52 52 52 67 2 1 22 20
output:
yes
result:
wrong answer expected NO, found YES [1st token]