QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#833306#9240. Mosaichansiyuan5 379ms29952kbC++173.1kb2024-12-26 17:01:422024-12-26 17:01:42

Judging History

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

  • [2024-12-26 17:01:42]
  • 评测
  • 测评结果:5
  • 用时:379ms
  • 内存:29952kb
  • [2024-12-26 17:01:42]
  • 提交

answer

#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define vi vector<int>
const int N=2e5+5;
vector<lol> ans;
int n,Q;
int a0[N],a1[N],b0[N],b1[N];
int a[N<<1];
int s[N<<1];
lol s1[N<<1],s2[N<<1];
lol get0(int l,int r){
    return s[r]-s[l-1];
}
lol get1(int l,int r){
    return (s1[r]-s1[l-1])-get0(l,r)*(l-1);
}
lol get2(int l,int r){
    return (s2[l]-s2[r+1])-get0(l,r)*(n-3+n-2-r);
}
lol work(int r,int c){
    if(r<=0 || c<=0) return 0;
    cout<<r<<' '<<c<<endl;
    if(r<=c)
        return get0(n-3+1,n-3+c-r)*r+get1(n-3-r+2,n-3)+get2(n-3+c-r+1,n-3+c);
    return get0(n-3-(r-c)+1,n-3)*c+get1(n-3-c+1,n-3-(r-c))+get2(n-3+1,n-3+c);
}
int A[5005][5005];
vector<lol> mosaic(vi X,vi Y,vi U,vi D,vi L,vi R){
    n = X.size();
    Q = U.size();
    if(n<=3){
        for(int i=0;i<n;i++) A[0][i]=X[i];
        for(int i=0;i<n;i++) A[i][0]=Y[i];
        for(int i=1;i<n;i++)
            for(int j=1;j<n;j++)
                A[i][j] = !(A[i-1][j]|A[i][j-1]);
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++){
                if(i) A[i][j] += A[i-1][j];
                if(j) A[i][j] += A[i][j-1];
                if(i&&j) A[i][j] -= A[i-1][j-1];
            }
        for(int i=1;i<n;i++) X[i]+=X[i-1];
        for(int i=0;i<Q;i++){
            lol res=0;
            if(U[i]==0 && D[i]==0){
                res = X[R[i]];
                if(L[i]) res-=X[L[i]-1];
            }
            else{
                res = A[D[i]][R[i]];
                if(U[i]) res -= A[U[i]-1][R[i]];
                if(L[i]) res -= A[D[i]][L[i]-1];
                if(U[i]&&L[i]) res += A[U[i]-1][L[i]-1];
            }
            ans.push_back(res);
            // cerr<<res<<endl;
        }
        return ans;
    }
    a0[0] = b0[0] = Y[0];
    a1[0] = Y[1];
    b1[0] = X[1];
    for(int i=1;i<n;i++){
        a0[i] = X[i];
        a1[i] = !(a1[i-1]|a0[i]);
        b0[i] = Y[i];
        b1[i] = !(b1[i-1]|b0[i]);
    }
    a[n-3+1] = !(a1[2]|b1[2]);
    for(int i=n-3;i>=1;i--){
        a[i] = !(b1[n-3-i+3]|a[i+1]);
    }
    for(int i=n-3+1;i<=n-3+n-2;i++){
        a[i] = !(a[i-1]|a1[i-(n-3)+1]);
    }
    a0[0] = a0[1] = a1[0] = a1[1] = 0;
    for(int i=1;i<=n;i++){
        a0[i]+=a0[i-1]; a1[i]+=a1[i-1];
        b0[i]+=b0[i-1]; b1[i]+=b1[i-1];
    }
    // for(int i=1;i<=n-3+n-2;i++) printf("%d",a[i]); puts("");
    for(int i=1;i<=n-3+n-2;i++)
        s[i] = s[i-1]+a[i];
    for(int i=1;i<=n-3+n-2;i++)
        s1[i] = s1[i-1]+1ll*a[i]*i;
    for(int i=n-3+n-2;i>=1;i--)
        s2[i] = s2[i+1]+1ll*a[i]*(n-3+n-2-i+1);
    for(int i=0;i<Q;i++){
        lol res=0;
        if(U[i]==0) res += a0[R[i]]-(L[i]==0? 0:a0[L[i]-1]);
        if(U[i]<=1) res += a1[R[i]]-(L[i]==0? 0:a1[L[i]-1]);
        if(L[i]==0) res += b0[D[i]]-(U[i]==0? 0:b0[U[i]-1]);
        if(L[i]<=1) res += b1[D[i]]-(U[i]==0? 0:b1[U[i]-1]);
        // cout<<res<<endl;
        res += work(D[i]-1,R[i]-1);
        res -= work(U[i]-2,R[i]-1);
        res -= work(D[i]-1,L[i]-2);
        res += work(U[i]-2,L[i]-2);
        ans.push_back(res);
    }
    return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3824kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
1
0
0
10
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
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:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
0
0
0
0
0
0
0
0
0
0

result:

ok 

Test #2:

score: 5
Accepted
time: 0ms
memory: 3812kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
1
1
1
10
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
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:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
1
1
1
1
1
1
1
1
1
1

result:

ok 

Test #3:

score: 5
Accepted
time: 0ms
memory: 3884kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
1 0
1 0
10
1 1 0 1
1 1 0 1
0 0 0 0
0 1 0 1
0 1 0 1
1 1 0 0
0 1 0 1
0 1 1 1
1 1 0 1
0 0 0 1

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
1
1
1
2
2
0
2
1
1
1

result:

ok 

Test #4:

score: 5
Accepted
time: 0ms
memory: 3856kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
1 0
1 0
10
0 1 1 1
0 1 0 1
0 1 0 0
1 1 0 1
0 1 0 1
0 1 0 0
1 1 1 1
0 0 0 1
0 1 0 0
1 1 0 0

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
1
2
1
1
2
1
1
1
1
0

result:

ok 

Test #5:

score: 5
Accepted
time: 0ms
memory: 4080kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
0 1
0 0
10
0 1 0 0
0 0 0 1
0 1 0 0
0 0 0 0
1 1 1 1
0 1 0 0
0 0 0 1
0 1 0 1
0 1 0 1
0 1 0 1

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
0
1
0
0
0
0
1
1
1
1

result:

ok 

Test #6:

score: 5
Accepted
time: 0ms
memory: 4084kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
1 1
1 0
10
0 0 0 1
0 0 0 1
1 1 0 1
0 1 0 1
0 1 0 0
0 1 1 1
1 1 0 1
0 0 1 1
0 1 0 0
0 1 0 0

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
2
2
0
2
1
1
0
1
1
1

result:

ok 

Test #7:

score: 5
Accepted
time: 0ms
memory: 3816kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
0 0
0 1
10
0 0 0 0
0 1 0 1
0 1 0 1
0 1 0 1
0 1 1 1
0 0 1 1
0 0 0 1
0 1 0 0
1 1 0 1
1 1 0 1

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
0
1
1
1
0
0
0
1
1
1

result:

ok 

Test #8:

score: 5
Accepted
time: 0ms
memory: 4116kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
1 0
1 1
10
0 1 0 0
1 1 0 1
0 0 0 1
1 1 1 1
1 1 0 0
0 1 1 1
0 1 0 0
0 0 1 1
1 1 0 1
0 1 0 1

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
2
1
1
0
1
0
2
0
1
2

result:

ok 

Test #9:

score: 5
Accepted
time: 0ms
memory: 3824kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
0 1
0 1
10
0 1 0 1
0 1 0 1
1 1 1 1
0 1 0 1
0 0 1 1
0 1 0 1
0 1 1 1
0 0 0 0
0 1 0 0
0 1 0 1

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
2
2
0
2
1
2
1
0
1
2

result:

ok 

Test #10:

score: 5
Accepted
time: 0ms
memory: 3804kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
2
1 1
1 1
10
0 0 0 1
0 1 0 0
0 1 0 0
0 1 0 1
0 0 0 0
0 1 0 1
0 1 0 1
0 1 1 1
0 1 0 1
1 1 1 1

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
2
2
2
3
1
3
3
1
3
0

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #11:

score: 0
Wrong Answer
time: 2ms
memory: 9924kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
199
0 0 1 0 0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 0 0 1...

output:

100 136
45 136
100 91
45 91
104 156
104 46
84 74
45 74
84 21
45 21
159 152
132 152
159 116
132 116
167 173
12 173
167 19
12 19
185 61
106 61
185 24
106 24
145 94
68 94
145 42
68 42
162 197
101 197
162 34
101 34
95 25
32 25
175 149
78 149
175 105
78 105
137 152
130 152
137 141
130 141
68 180
49 180
6...

result:

wrong answer secret mismatch

Subtask #3:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 64ms
memory: 29952kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
199999
0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0 0 0 0 ...

output:

Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9
OK
2210
132110
22036
105836
45191
144168
35165
88467
24088
23177
109895
111508
22254
39828
61771
94346
116336
108213
123502
69557
84505
2297
108812
97420
40575
97235
48897
98655
64973
8246
100817
38957
100565
21387
42808
13584
28336
93597
18163
12068
50319
122693
926...

result:

wrong answer 3rd lines differ - on the 1st token, expected: '1314', found: '2210'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 127ms
memory: 16872kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
200000
1 7 0 4
3 4 3 4
3 6 2 5
4 5 6 7
5 7 2 8
0 6 4 7
0 5 6 7
1 3 9 9
6 9 1 7
2 9 4 6
4 4 6 7
0 1 8 8
7 7 0 3
0 4 1 7
2 2 0 9
3 9 4 6
3 9 0 9
1 8 4 6
4 5 5 7
0 6 2 3
2 3 0 6
1 9 8 8
2 4 3 4
3 6 2 9
3 9 2 7
1 3 0 3
0 8 2 4
3...

output:

6 3
3 3
1 3
3 1
1 1
5 4
1 4
4 6
2 6
4 4
2 4
6 7
3 7
5 6
5 2
4 6
4 4
2 8
2 7
8 6
4 6
8 5
8 2
3 6
2 6
3 4
2 4
6 2
5 2
3 6
1 8
8 5
1 5
8 2
1 2
8 8
1 8
7 5
7 2
4 6
2 6
4 3
2 3
5 2
2 5
8 7
8 6
3 3
3 1
5 8
1 8
8 6
1 6
2 2
7 3
4 5
1 5
4 1
1 1
8 1
1 1
8 6
1 6
8 3
1 3
7 2
7 6
7 5
3 4
2 1
6 5
4 5
7 4
1 4
4 8
...

result:

wrong answer secret mismatch

Subtask #6:

score: 0
Wrong Answer

Test #42:

score: 0
Wrong Answer
time: 379ms
memory: 28492kb

input:

njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq
199999
0 1 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 1 1 0 0 0 0 1 0 1 ...

output:

110910 49393
110909 49393
110910 49392
110909 49392
23174 74297
23173 74297
23174 74296
23173 74296
75424 161963
75423 161963
75424 161962
75423 161962
121661 157325
121660 157325
121661 157324
121660 157324
122789 182822
122788 182822
122789 182821
122788 182821
139278 34613
139277 34613
139278 346...

result:

wrong answer secret mismatch

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%