QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#783722 | #7717. Bitsets | WRuperD | TL | 2437ms | 43792kb | C++14 | 3.8kb | 2024-11-26 11:31:43 | 2024-11-26 11:31:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 1e6 + 10;
int n, m;
inline int to(int x, int y){
if(x <= 0) return 0;
return (x - 1) * m + y;
}
int a[MAX];
namespace subtask1{
int s[MAX];
void solve(){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[to(i, j)]) s[to(i, j)] = 1;
if(i == 1) continue;
s[to(i, j)] += s[to(i - 1, j)];
}
}
int k = read();
int X = read(), Y = read(), Z = read();
int l = 1, r = n;
int A = 1, B = n;
int ret = 0;
while(k--){
int ans = 0;
for(int i = 1; i <= m; i++){
int cnt = s[to(r, i)] - s[to(l - 1, i)];
if(cnt == 0 or cnt == r - l + 1){
ans++;
}
}
ret += ans;
A = (A * X + ans * Y + Z) % n + 1;
B = (B * Y + ans * Z + X) % n + 1;
l = min(A, B), r = max(A, B);
}
write(ret), endl;
}
}
namespace subtask2{
bitset <100001> bt[405];
bitset <100001> bt2[405];
int ans[405][405];
void solve(){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
bt[i][j] = a[to(i, j)];
bt2[i][j] = (a[to(i, j)] ^ 1);
}
}
for(int i = 1; i <= n; i++){
bitset <100001> now;
for(int j = i; j >= 1; j--){
now = now | bt[j];
ans[j][i] += (m - now.count());
}
}
for(int i = 1; i <= n; i++){
bitset <100001> now;
for(int j = i; j >= 1; j--){
now = now | bt2[j];
ans[j][i] += (m - now.count());
}
}
int k = read();
int X = read(), Y = read(), Z = read();
int l = 1, r = n;
int A = 1, B = n;
int ret = 0;
while(k--){
int Ans = ans[l][r];
ret += Ans;
// write(l), put(), write(r), put(), write(Ans), endl;
A = (A * X + Ans * Y + Z) % n + 1;
B = (B * Y + Ans * Z + X) % n + 1;
l = min(A, B), r = max(A, B);
}
write(ret), endl;
}
}
namespace subtask3{
const int MAX2 = 5e3 + 10;
bitset <2505> f[14][MAX2];
bitset <2505> f2[14][MAX2];
int lg2[MAX];
void solve(){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
f[0][i][j] = a[to(i, j)];
f2[0][i][j] = (a[to(i, j)] ^ 1);
}
}
for(int i = 1; i < 14; i++){
for(int j = 1; j + (1ll << i) - 1 <= n; j++){
f[i][j] = f[i - 1][j] | f[i - 1][j + (1ll << (i - 1))];
}
}
for(int i = 1; i < 14; i++){
for(int j = 1; j + (1ll << i) - 1 <= n; j++){
f2[i][j] = f2[i - 1][j] | f2[i - 1][j + (1ll << (i - 1))];
}
}
for(int i = 2; i <= n; i++){
lg2[i] = lg2[i >> 1] + 1;
}
int k = read();
int X = read(), Y = read(), Z = read();
int l = 1, r = n;
int A = 1, B = n;
int ret = 0;
while(k--){
int Ans = 0;
int len = (r - l + 1);
len = lg2[len];
Ans += m - (f[len][l] | f[len][r - (1ll << len) + 1]).count();
Ans += m - (f2[len][l] | f2[len][r - (1ll << len) + 1]).count();
// int Ans = ans[l][r];
ret += Ans;
A = (A * X + Ans * Y + Z) % n + 1;
B = (B * Y + Ans * Z + X) % n + 1;
l = min(A, B), r = max(A, B);
}
write(ret), endl;
}
}
mt19937 Rnd(time(0));
void solve(){
n = read(), m = read();
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
char ch = getchar();
while(ch != '0' and ch != '1') ch = getchar();
a[to(i, j)] = ch - '0';
// a[to(i, j)] = Rnd() % 2;
}
}
if(n <= 400){
subtask2::solve();
}else if(m <= 200){
subtask1::solve();
}else{
subtask3::solve();
}
return ;
}
signed main(){
int t = 1;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9960kb
input:
4 10 1010110101 0101111001 1101101101 1011010000 4 10 5 4
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9860kb
input:
6 3 110 011 010 100 101 111 5 7 5 5
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 2ms
memory: 10100kb
input:
10 10 1100101001 0011100101 1100001110 0101011100 1001011010 0010101101 1001011011 0010110000 1001100111 0010101000 10 11 11 11
output:
26
result:
ok 1 number(s): "26"
Test #4:
score: 0
Accepted
time: 1ms
memory: 10124kb
input:
6 7 1101001 1000110 0010000 1110001 1110100 0001011 15 7 5 7
output:
30
result:
ok 1 number(s): "30"
Test #5:
score: 0
Accepted
time: 0ms
memory: 10032kb
input:
10 13 0101011101010 0100000011001 0001101010111 1101000111100 1001110000110 0110011000110 1101101110100 0101101110011 0000100011100 1100010110100 20 11 11 11
output:
60
result:
ok 1 number(s): "60"
Test #6:
score: 0
Accepted
time: 0ms
memory: 9880kb
input:
12 15 010010101101011 010000100100011 110011010100011 111011101010111 101110111010100 100000111011011 010100001101100 001011010111100 000011011100010 101100101001010 010000111101111 110100011011000 25 11 13 13
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 2ms
memory: 10152kb
input:
15 16 1111010001110110 1111100101111111 1111111111001010 0010100111111001 1011011000001000 1111000101000000 1001101100100011 0010111000001110 0011111000010001 1000011111011111 1101000111000001 0010010100001011 1110001111111010 0011100110100001 0101110010101101 30 13 13 17
output:
448
result:
ok 1 number(s): "448"
Test #8:
score: 0
Accepted
time: 2ms
memory: 7836kb
input:
13 15 001100110010010 011100110100111 111100000000110 111000011101010 111100011001010 100111101001001 000110010111101 100101000000100 011010001000000 101001100011100 011110111111000 010110111100111 110010010100110 35 13 13 11
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 2ms
memory: 10040kb
input:
11 9 110101001 001010011 000100101 110011000 110101110 001001100 110100110 100110000 100010111 110110000 111100000 40 13 11 13
output:
47
result:
ok 1 number(s): "47"
Test #10:
score: 0
Accepted
time: 1ms
memory: 7828kb
input:
10 18 010111010010010001 111010101000100111 011010111100011001 000010000111001111 101010010000110100 001110000101111101 010101011011000100 111011110001010010 111010101101000000 100101010111101100 45 11 11 11
output:
353
result:
ok 1 number(s): "353"
Test #11:
score: 0
Accepted
time: 2ms
memory: 10040kb
input:
11 17 01100000011010100 11100001111000101 10011100111011011 10011110010011000 10110110111110010 01001001101111000 11010101101101110 01101101110001110 11101000000101001 00000110000001000 10001111001100010 50 13 11 13
output:
228
result:
ok 1 number(s): "228"
Test #12:
score: 0
Accepted
time: 1ms
memory: 10096kb
input:
1 1 0 1 2 2 2
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 9852kb
input:
1 10 0010001000 1 2 2 2
output:
10
result:
ok 1 number(s): "10"
Test #14:
score: 0
Accepted
time: 0ms
memory: 9944kb
input:
10 1 0 0 0 0 1 0 0 0 1 0 1 11 11 11
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 48ms
memory: 10308kb
input:
100 100 0001000000000000100100100100000000100100100010000000000000000000000010000000000010001000000000000000 0000000000000000000000000000000000000000000000000000000000100000010000000010001000000100001000000000 000000000000000000000000000001000000010001000000000000000000000000000000100000000000001000...
output:
709
result:
ok 1 number(s): "709"
Test #16:
score: 0
Accepted
time: 0ms
memory: 34632kb
input:
500 500 1011111111111111111111111111011111110111111101111111111111111111111101111111111111111111111111111111011111111111111101111110101111111111111111101111111111111101110101111111110111111101111111111110111100111111101111111101011111111111111111111111111111111111111011111101111111111111111111111111...
output:
1394
result:
ok 1 number(s): "1394"
Test #17:
score: 0
Accepted
time: 9ms
memory: 43792kb
input:
1000 1000 00000000000000000000000000010000001110000000001000000100000000000000000000000000000000000001000000001000000000000000000000000000000000100010000000000000000000000000000000100000100100100100000000000000000000000000001100000000000001100000000000000000000000000000010000100000000000010000000000...
output:
21974
result:
ok 1 number(s): "21974"
Test #18:
score: 0
Accepted
time: 9ms
memory: 20604kb
input:
10000 100 1110111111110111111111111111111111011111111111011111111011111111111011111111111111111101111111111111 1110111101111111111111111111111111111111110111111111111111111111011111111101111111111111111111111111 1111110111111111111111111111011111111111111111111111111111111111111111111101111111111111...
output:
3586
result:
ok 1 number(s): "3586"
Test #19:
score: 0
Accepted
time: 58ms
memory: 18376kb
input:
100 10000 00110000010011110000100010110001110000001000010010110100001100010000011100100001111000000010000001000100101001000000010101001100000010100011011001000101001110000100100100100110000111010100000000101000001100011001101101011000010001110110000010010000000000000011101101100010110010100111000011...
output:
1046213
result:
ok 1 number(s): "1046213"
Test #20:
score: 0
Accepted
time: 31ms
memory: 20348kb
input:
5000 200 11000000100100000000000010001000000000000000000000000000010000000000000000000001000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000100000000000000000000000000010000000000000000000000010000000100000000000100000001000...
output:
170424
result:
ok 1 number(s): "170424"
Test #21:
score: 0
Accepted
time: 243ms
memory: 21160kb
input:
5000 200 00000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000000010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000100000000000000001000010000000000000000000100000001000000000001000000000100000000000010...
output:
2499626
result:
ok 1 number(s): "2499626"
Test #22:
score: 0
Accepted
time: 2437ms
memory: 19748kb
input:
5000 200 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000010000100000000000 000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000...
output:
35029587
result:
ok 1 number(s): "35029587"
Test #23:
score: -100
Time Limit Exceeded
input:
5000 200 00000000000000000000000000000000000000000010000000000000000000000000000000000000000000100000000010000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000 000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000...