QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314643#7782. Ursa MinorDelay_for_five_minutesWA 71ms56916kbC++205.5kb2024-01-26 01:50:352024-01-26 01:50:35

Judging History

你现在查看的是最新测评结果

  • [2024-01-26 01:50:35]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:56916kb
  • [2024-01-26 01:50:35]
  • 提交

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 = (1<<31)-1;
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 (((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) + 2 , 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(B+2,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") ;
    while(q--) {
        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) {
                int sum = 0;
                int s0 = 0;
                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(s0 == sum) cout << "Yes\n" ;
                else cout << "No\n" ;
            }
            else {
                int sum = S[k].qry(l , r);
                if(sum == 0) cout << "Yes\n";
                else cout << "No\n" ;
            }
        }
        else {
            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()
{
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    int T = 1;
    while(T--) solv();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 24060kb

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: 0ms
memory: 24172kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: -100
Wrong Answer
time: 71ms
memory: 56916kb

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:

wrong answer 417th words differ - expected: 'Yes', found: 'No'