QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314652 | #7782. Ursa Minor | Delay_for_five_minutes | TL | 2765ms | 374356kb | C++20 | 6.5kb | 2024-01-26 02:09:02 | 2024-01-26 02:09:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n , m , q;
const int bs = 7797;
const int mod = 1e9 + 7;
int a[200005] ;
int st[20][200005];
int qry(int l,int r) {
int k = __lg(r - l + 1) ;
return __gcd(st[k][l] , st[k][r - (1<<k) + 1]) ;
}
int pw[200005] , prep[200005];
struct ST1 {
int pr[505] ; //前缀和
int block[200005]; // 所属块
int pre[505][505] ;///每块前缀和
int L[505] , R[505];
int a[200005];
int B;
void init() {
for(int i = 1;i <= n;i++) {
block[i] = block[i - 1];
if(B == 1 || i % B == 1) {
block[i]++ ;
R[block[i - 1]] = i - 1;
L[block[i]] = i;
}
}
R[block[n]] = n ;
for(int i = 1;i <= block[n];i++) {
for(int j = L[i] ; j <= R[i] ;j++) {
pre[i][j - L[i] + 1] = (pre[i][j - L[i]] + a[j]) % mod;
}
pr[i] = (pr[i - 1] + pre[i][R[i] - L[i] + 1]) % mod;
}
}
void upd(int pos,int v) {
a[pos] = v;
int i = block[pos] ;
for(int j = pos ; j <= R[i] ;j++) {
pre[i][j - L[i] + 1] = (pre[i][j - L[i]] + a[j]) % mod;
}
for(int j = i ; j <= block[n];j++) pr[j] = (pr[j - 1] + pre[j][R[j] - L[j] + 1]) % mod;
}
int qry(int l,int r) {
int bl = block[l] , br = block[r] ;
if(bl == br) {
return (pre[bl][r - L[bl] + 1] - pre[bl][l - L[bl]] + mod ) % mod;
}
return ((pre[br][r - L[br] + 1] - pre[bl][l - L[bl]]
+ pr[br - 1] - pr[bl - 1])%mod + mod ) % mod;
// return (((ll)pre[bl][R[bl] - L[bl] + 1] - pre[bl][l - L[bl]]
// +pre[br][r - L[br] + 1] + pr[br - 1] - pr[bl])%mod + mod ) % mod;
}
}s1;
struct ST2 {
int a[200005];
int pr[505];
int B;
void init() {
int cnt = 0;
for(int i = 1;i <= n;i++) {
if(i % B == 1 || B == 1) ++cnt;
pr[cnt] = (pr[cnt] + a[i]) % mod;
}
}
void upd(int pos,int v) {
int id = (pos - 1) / B + 1;
pr[id] = ((ll)pr[id] - a[pos] + v + mod) % mod;
a[pos] = v;
return ;
}
int qry(int l,int r) {
int idl = (l - 1) / B + 1 , idr = (r - 1) / B + 1;
if(idl == idr) {
int ans = 0;
for(int j = l;j <= r;j++) ans = (ans + a[j]) % mod;
return ans;
}
int ans = 0;
if(l > idl * B - B/2) {
for(int j = l;j <= idl*B;j++) ans = (ans + a[j]) % mod;
}
else {
ans = (ans + pr[idl]) % mod;
for(int j = (idl-1)*B + 1 ; j < l;j++) ans = (ans - a[j]) % mod;
ans = (ans + mod) % mod;
}
if(r > idr*B - B/2) {
ans = (ans + pr[idr]) % mod;
for(int j = r + 1;j <= idr*B;j++) ans = (ans - a[j]) % mod;
ans = (ans + mod) % mod;
}
else{
for(int j = (idr-1)*B + 1 ; j <= r;j++) ans = (ans + a[j]) % mod;
}
for(int j = idl + 1; j <= idr - 1;j++) ans = (ans + pr[j]) % mod;
return ans;
}
}S[450];
void solv()
{
cin >> n >> m >> q;
pw[0] = 1; prep[0] = 1;
for(int i = 1;i <= n;i++) {pw[i] = 1LL * pw[i - 1] * bs % mod; prep[i] = (prep[i - 1] + pw[i]) % mod;}
for(int i = 1;i <= n;i++) {cin >> a[i] ;}
for(int i = 1;i <= m;i++) {
cin >> st[0][i] ;
}
for(int i = 1;i <= 19;i++) {
for(int j = 1;j <= m;j++) {
if(j + (1 << i - 1) <= m) st[i][j] = __gcd(st[i - 1][j] , st[i - 1][j + (1 << i - 1)]) ;
else st[i][j] = st[i - 1][j] ;
}
}
s1.B = min((int)sqrt(n) + 5 , n);
int B = sqrt(n) ;
for(int i = 1;i <= n;i++) s1.a[i] = 1LL * pw[n - i] * a[i] % mod;
s1.init() ;
for(int k = 1;k <= B;k++) {
S[k].B = min((int)sqrt(n) + 5 , n);
for(int i = 1;i <= n;i++) {
S[k].a[i] = 1LL * a[i] * pw[i % k] % mod;
if(i % k == 0) S[k].a[i] = (S[k].a[i] - 1LL * a[i] * prep[k - 1]%mod + mod) % mod;
}
S[k].init() ;
}
// puts("ojbk") ;
int n0 = 0 , n1 = 0 , n2 = 0;
for(int x= 1;x <= q;x++){
// if(m == 199999 && x == 90000) {
// cout << n0 <<' ' << n1 <<' ' << n2 <<' ' << B << '\n' ;
// exit(0) ;
// }
char op ; cin >> op ;
if(op == 'Q') {
int l , r , s , t;
cin >> l >> r >> s >> t;
int k = __gcd(r - l + 1 , qry(s , t)) ;
if(k > B) {
n0++;
int sum = 0;
int s0 = 0 , ql = l, qr = l + k - 1;
for(int i = 0 ; i < (r - l + 1) / k ; i++) {
sum = (sum + 1LL * s1.qry(ql, qr) * pw[i * k]) % mod;
s0 = (s0 + a[ql]) % mod;
ql += k ; qr += k;
}
// for(int i = 0 ; i < (r - l + 1) / k ; i++) {
// sum = (sum + 1LL * s1.qry(l+ i * k , l + (i + 1)*k - 1) * pw[i * k]) % mod;
// s0 = (s0 + a[l + i * k]) % mod;
// }
if(l + k <= n) s0 = 1LL * s0 * (prep[n - l] - prep[n - l - k] + mod) % mod;
else s0 = 1LL * s0 * prep[n - l] % mod;
// if(m != 199999) {
if(s0 == sum) cout << "Yes\n" ;
else cout << "No\n" ;
// }
}
else {
n1++;
int sum = S[k].qry(l , r);
// if(m != 199999) {
if(sum == 0) cout << "Yes\n";
else cout << "No\n" ;
// }
}
}
else {
n2++;
int u , v ; cin >> u >> v;
a[u] = v;
s1.upd(u , 1LL * a[u] * pw[n - u] % mod) ;
// puts("ojbk??") ;
for(int k = 1;k <= B;k++) {
int val = 1LL * a[u] * pw[u % k] % mod;
if(u % k == 0) val = (val - 1LL * a[u] * prep[k - 1]%mod + mod) % mod;
S[k].upd(u , val);
}
// puts("ojbk") ;
}
}
return;
}
int main()
{
// freopen("in.txt","r",stdin) ;
// freopen("out.txt","w",stdout) ;
ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
int T = 1;
clock_t st = clock() ;
while(T--) solv();
// cerr << (double)(clock()- st) / CLOCKS_PER_SEC << '\n' ;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5852kb
input:
6 4 5 1 1 4 5 1 4 3 3 2 4 Q 1 5 1 2 Q 2 5 3 4 U 5 2 Q 1 6 1 2 Q 2 5 3 4
output:
Yes No No Yes
result:
ok 4 tokens
Test #2:
score: 0
Accepted
time: 1ms
memory: 5796kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 76ms
memory: 6788kb
input:
2000 2000 200000 1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...
output:
Yes Yes No Yes Yes No No No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes No Yes Yes No No No No No Yes No No No Yes Yes No Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes No Yes Yes Yes No No Yes No Yes No No No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes No...
result:
ok 100554 tokens
Test #4:
score: 0
Accepted
time: 49ms
memory: 20816kb
input:
1 200000 200000 998244353 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
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 100240 tokens
Test #5:
score: 0
Accepted
time: 39ms
memory: 15536kb
input:
6 131072 200000 0 0 0 0 1000000000 1000000000 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...
output:
Yes Yes Yes No No No Yes No No No No No Yes Yes No Yes No Yes Yes Yes No No No No No No No Yes No No No Yes Yes Yes Yes Yes Yes Yes Yes No No No No Yes 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 No No No No No Yes No No No No No No Yes Yes No Yes N...
result:
ok 100021 tokens
Test #6:
score: 0
Accepted
time: 1157ms
memory: 374176kb
input:
200000 200000 200000 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...
output:
No No No No No No No No No No No No No No Yes No No No Yes No No No No No No No No No No No No No No Yes No No No No No Yes Yes Yes No No No No No No No No Yes 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 Yes No Yes Yes No No No No No No No No N...
result:
ok 187340 tokens
Test #7:
score: 0
Accepted
time: 926ms
memory: 374260kb
input:
200000 200000 200000 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531...
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 199985 tokens
Test #8:
score: 0
Accepted
time: 944ms
memory: 374356kb
input:
200000 200000 200000 793134805 922104801 158394038 993313213 77527653 992889267 148461787 499165677 132176015 189185554 783374975 332147281 923925325 371040161 393285793 437388761 138662855 212488140 265392646 498903298 578518594 550390771 960084339 408548934 56106823 814997309 456913457 300689692 1...
output:
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 Yes 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 No No No No No No No No No No No Yes No...
result:
ok 200000 tokens
Test #9:
score: 0
Accepted
time: 932ms
memory: 374336kb
input:
200000 200000 200000 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037...
output:
No No No No Yes No Yes No No No No Yes No No No Yes No Yes No No No No No No No No No No No No No No Yes No No No No No No No Yes No No Yes No Yes No Yes No Yes No No No No Yes No No Yes No No No No No No No No Yes No Yes No No No No Yes No Yes No No Yes No Yes No No No Yes No No No No No No No No N...
result:
ok 199977 tokens
Test #10:
score: 0
Accepted
time: 1441ms
memory: 374296kb
input:
200000 200000 200000 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606...
output:
No No No Yes No No No No No No No No No No No No Yes No No Yes No No No No No No No No No No Yes No No No No Yes No No No No No No No No Yes No No No No No No No No No No No No Yes No No No Yes No No No No No No No Yes No No No No No No No No No Yes No No No No No No No No No Yes No No No No No No N...
result:
ok 100329 tokens
Test #11:
score: 0
Accepted
time: 2743ms
memory: 374296kb
input:
200000 199999 200000 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886...
output:
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 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:
ok 100000 tokens
Test #12:
score: 0
Accepted
time: 2581ms
memory: 374220kb
input:
199997 199989 199999 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047...
output:
Yes Yes No No No No No No Yes No No No No No Yes No Yes No Yes No No Yes No No No No No No No No Yes No No No No Yes No Yes No Yes Yes Yes No Yes No No No No No No Yes Yes Yes Yes Yes No Yes No No No Yes Yes No No No No No No No No No No Yes Yes No No No No Yes Yes No Yes No No No No No No No Yes No...
result:
ok 100000 tokens
Test #13:
score: 0
Accepted
time: 2765ms
memory: 374200kb
input:
200000 199899 200000 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100...
output:
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 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:
ok 100000 tokens
Test #14:
score: 0
Accepted
time: 2113ms
memory: 374308kb
input:
200000 199990 200000 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491...
output:
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 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:
ok 100000 tokens
Test #15:
score: 0
Accepted
time: 739ms
memory: 374340kb
input:
200000 200000 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
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 200000 tokens
Test #16:
score: 0
Accepted
time: 707ms
memory: 374300kb
input:
200000 200000 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
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 200000 tokens
Test #17:
score: 0
Accepted
time: 1889ms
memory: 374304kb
input:
200000 200000 200000 136241709 121069654 74104428 402269028 289305416 855066384 59173243 188019353 669781180 986996513 504339812 329791320 25125974 222565943 288337442 964609791 466878029 264002600 189175389 9157365 469615339 896075603 753652692 122288279 240727003 784469217 906985969 890794301 2169...
output:
result:
ok 0 tokens
Test #18:
score: 0
Accepted
time: 1227ms
memory: 374112kb
input:
200000 200000 200000 273240622 378627620 579491720 693306037 632472065 511340335 670989889 554488479 652467925 278524470 836147563 424777678 759339952 855362660 230757613 865543002 560326470 755302163 785969817 6168093 585297358 945522008 799833815 740595138 24393108 602846463 227643614 845760733 81...
output:
result:
ok 0 tokens
Test #19:
score: 0
Accepted
time: 1876ms
memory: 374232kb
input:
200000 200000 200000 902784461 118694875 998774623 411874728 685597851 368044897 72498166 42228570 960589282 760858636 63223215 20140256 256927497 432494553 374529608 902188891 898994 969710880 697644219 743838599 684197754 515142816 492082738 409457048 326043554 219156706 376310102 878117528 358651...
output:
result:
ok 0 tokens
Test #20:
score: 0
Accepted
time: 2451ms
memory: 374300kb
input:
200000 200000 200000 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584...
output:
Yes No Yes No Yes No No No Yes No No No No No No No Yes No Yes Yes No No Yes No No No No No Yes Yes No No No No Yes No Yes No Yes No Yes No Yes No No No No No No No Yes No No No No No Yes No No No Yes No Yes No Yes No Yes No Yes No No No No No Yes No No No No Yes Yes No Yes No Yes No Yes No No No Ye...
result:
ok 100000 tokens
Test #21:
score: 0
Accepted
time: 2685ms
memory: 360736kb
input:
194304 200000 200000 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896 959184896...
output:
Yes No 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
result:
ok 28 tokens
Test #22:
score: -100
Time Limit Exceeded
input:
199996 15 200000 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935181296 935...