QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642842 | #9302. Caesar Cipher | Ashbourne | WA | 948ms | 33408kb | C++20 | 4.3kb | 2024-10-15 16:33:47 | 2024-10-21 09:40:14 |
Judging History
你现在查看的是测评时间为 2024-10-21 09:40:14 的历史记录
- [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-15 16:33:47]
- 提交
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define drp(i, j, k) for(int i = j; i >= k; -- i)
#define pii pair<int, int>
using namespace std;
const int N = 5e5 + 10;
const int Mod = 65536, M1 = 998244353, M2 = 1e9 + 7;
// #define ls(x) (x << 1)
// #define rs(x) (x << 1 | 1)
// struct SGT {
// pii tr[N << 2];
// void upd (int x) {
// tr[x] = tr[ls(x)] + tr[rs(x)];
// }
// void build(int x, int l, int r, vector<int> &in) {
// if (l == r) return tr[x] = in[l - 1], void();
// int mid = (l + r) >> 1;
// build (ls(x), l, mid, in);
// build (rs(x), mid + 1, r, in);
// upd (x);
// }
// void modify(int x, int l, int r, int cur, int val){
// if(l == r){
// tr[x] = tr[x] + val;
// return;
// }
// int mid = (l + r) >> 1;
// if(cur <= mid) modify(ls(x), l, mid, cur, val);
// else modify(rs(x), mid + 1, r, cur, val);
// upd(x);
// }
// int query(int x, int l, int r, int L, int R) {
// if (L <= l && r <= R) return tr[x];
// int mid = (l + r) >> 1;
// if (R <= mid) return query(ls(x), l, mid, L, R);
// if (L > mid) return query(rs(x), mid + 1, r, L, R);
// return query(ls(x), l, mid, L, R) + query(rs(x), mid + 1, r, L, R);
// }
// } Tr;
int fpow(int a, int b, int M){
int x = 1;
while(b){
if(b & 1)x = x * a % M;
a = a * a % M;
b >>= 1;
}
return x;
}
struct BST{
int tot, Mod;
void resize(int n, int m){
tot = n;
Mod = m;
}
int tr[N << 1];
void init(){
memset(tr, 0, sizeof tr);
}
void add(int x, int num){
if(x == 0) return;
while(x <= tot){
tr[x] += num;
tr[x] %= Mod;
x += x & (-x);
}
}
int query(int x){
int ans = 0;
while(x){
ans += tr[x];
ans %= Mod;
x -= x & (-x);
}
return ans;
}
}bst, tr1, tr2;
void solve(){
int n, q;
cin >> n >> q;
// cout << n << q << endl;
bst.resize(n, Mod);
vector<int> a(n + 1), b(n + 1), w1(n + 1), w2(n + 1);
for(int i = 1; i <= n; ++ i){
cin >> a[i];
}
bst.add(1, a[1]);
rep(i, 1, n - 1) b[i] = (a[i + 1] - a[i] + Mod) % Mod, bst.add(i + 1, b[i]);
int p1 = 70067, p2 = 70379;
tr1.resize(n - 1, M1);
tr2.resize(n - 1, M2);
w1[1] = w2[1] = 1;
for(int i = 1; i <= n - 1; ++ i){
w1[i + 1] = w1[i] * p1 % M1;
w2[i + 1] = w2[i] * p2 % M2;
tr1.add(i, w1[i] * b[i] % M1);
tr2.add(i, w2[i] * b[i] % M2);
}
while(q--){
int cc; cin >> cc;
if(cc == 2){
int x, y, len;
cin >> x >> y >> len;
int a1 = bst.query(x), a2 = bst.query(y);
if(a1 != a2){
cout << "no" << endl;
continue;
}
int hs1 = tr1.query(x + len - 2) + M1 - tr1.query(x - 1);
hs1 %= M1; hs1 = hs1 * fpow(w1[x], M1 - 2, M1) % M1;
int hs2 = tr2.query(x + len - 2) + M2 - tr2.query(x - 1);
hs2 %= M2; hs2 = hs2 * fpow(w2[x], M2 - 2, M2) % M2;
int hs3 = tr1.query(y + len - 2) + M1 - tr1.query(y - 1);
hs3 %= M1; hs3 = hs3 * fpow(w1[y], M1 - 2, M1) % M1;
int hs4 = tr2.query(y + len - 2) + M2 - tr2.query(y - 1);
hs4 %= M2; hs4 = hs4 * fpow(w2[y], M2 - 2, M2) % M2;
// cout << hs1 << " " << hs3 << endl;
// cout << fpow(w1[y], M1 - 2, M1) * w1[y] % M1 << endl;
if(hs1 == hs3 && hs2 == hs4){
cout << "yes" << endl;
}else cout << "no" << endl;
}else{
int l, r;
cin >> l >> r;
bst.add(l, 1); bst.add(r + 1, Mod - 1);
if(l != 1){
b[l - 1] ++;
tr1.add(l - 1, w1[l - 1] % M1);
tr2.add(l - 1, w2[l - 1] % M2);
if(b[l - 1] >= Mod){
b[l - 1] -= Mod;
tr1.add(l - 1, (M1 - Mod) * w1[l - 1] % M1);
tr2.add(l - 1, (M2 - Mod) * w2[l - 1] % M2);
}
}
if(r != n){
b[r] --;
tr2.add(r, w2[r] * (M2 - 1) % M2);
tr1.add(r, w1[r] * (M1 - 1) % M1);
if(b[r] < 0){
b[r] += Mod;
tr2.add(r, w2[r] * (Mod) % M2);
tr1.add(r, w1[r] * (Mod) % M1);
}
}
}
}
}
signed main(){
ios::sync_with_stdio(0);
int T = 1;
// cin >> T;
while(T--){
solve();
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7692kb
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: 1ms
memory: 7644kb
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: 3ms
memory: 7916kb
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: 138ms
memory: 11812kb
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: 948ms
memory: 32156kb
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: 603ms
memory: 33408kb
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: 635ms
memory: 32520kb
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: 427ms
memory: 32908kb
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: 266ms
memory: 30960kb
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: 438ms
memory: 32652kb
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: 220ms
memory: 31092kb
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: 29ms
memory: 19208kb
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: 0
Extra Test Passed