QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84183 | #3060. Cumulative Code | zhaohaikun | WA | 12ms | 57208kb | C++14 | 4.5kb | 2023-03-05 21:14:06 | 2023-03-05 21:14:07 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
int k, q, a, d, m;
struct zhk {
ll k, b, y;
zhk (ll _k = 0, ll _b = 0, ll _y = 0) {
k = _k;
b = _b;
y = _y;
}
friend zhk operator + (const zhk& x, const zhk& y) {
return (zhk) {x.k + y.k, x.b + y.b, x.y + y.y};
}
friend zhk& operator += (zhk &x, const zhk& y) {
return (x = x + y);
}
} f[2][35][1 << 15];
zhk work(zhk x, int y) {
return (zhk) {0, x.k * y + x.b, x.y};
}
zhk ls(zhk x) {
return (zhk) {x.k << 1, x.b, x.y};
}
zhk rs(zhk x) {
// if (x.y < 1) return (zhk) {x.k << 1, x.b, x.y};
return (zhk) {x.k << 1, x.b + x.k / 2, x.y};
}
ll calc(ll x, ll y) {
// cout << x << " " << y << endl;
bool flag = true;
zhk ans;
int z = 1;
F(i, 1, k - 1) {
// cout << ans.y << " " << ans.b << " " << z << " " << i + 1 << " " << x << " " << f[0][i + 1][x].k << " " << f[0][i + 1][x].b << " " << f[0][i + 1][x].y << " " << y << endl;
if ((ans + f[0][i + 1][x]).y <= y) {
// cout << "! " << f[0][i + 1][x].k << " " << f[0][i + 1][x].b << endl;
// exit(0);
ans += work(f[0][i + 1][x], z);
// cout << i + 1 << " " << ans.b << endl;
// cout << x << " " << i << " " << k << " " << (1 << (k - i)) - 1 << endl;
x = ((x - ((1 << (k - i)) - 1)) % d + d) % d;
// cout << x << endl;
if (flag) {
if (ans.y < y && x == 1 % d) ans += (zhk) {0, z * 2 + 1, 1};
x = (x - 1 + d) % d;//, cout << z * 2 + 1 << endl;
} else {
if ((ans + f[flag][i + 1][x]).y <= y) {
ans += work(f[flag][i + 2][x], z * 2 + 1);
x = ((x - ((1 << (k - i - 1)) - 1)) % d + d) % d;
ans += work(f[flag][i + 2][x], z * 2 + 1);
x = ((x - ((1 << (k - i - 1)) - 1)) % d + d) % d;
if (x == 1 % d) ans += (zhk) {0, z, 1};
// cout << ans.b << endl;
break;
}
}
z = z << 1 | 1;
} else flag = false, z <<= 1;
}
// cout << "ANS: " << ans.b << endl;
return ans.b;
}
int query(int x) {
int z = 1;
bool flag = true;
F(i, 1, k) {
// cout << i << " " << x << endl;
if (flag) {
if ((1 << (k - i)) == x) return z << 1 | 1;
} else {
if ((1 << (k - i + 1)) - 1 == x) return (z >> 1);
}
if ((1 << (k - i)) - 1 >= x) {
z <<= 1;
flag = false;
} else {
x -= (1 << (k - i)) - 1;
if (flag) x--;
z = z << 1 | 1;
}
}
assert(0); return -1;
}
signed main() {
read(k); read(q);
while (q--) {
read(a); read(d); read(m);
if (d <= (1 << 15)) {
DF(i, k, 1) {
F(j, 0, d - 1) f[0][i][j] = f[1][i][j] = (zhk) {0, 0, 0};
// if (i == k) {
// f[0][i][1 % d] = (zhk) {1, 0, 1};
// f[1][i][1 % d] = (zhk) {2, 1, 1};
// continue;
// }
if (i != k) {
F(j, 0, d - 1) {
// cout << f[0][i + 1][j].y << endl;
f[0][i][j] += ls(f[0][i + 1][j]);
f[1][i][j] += ls(f[0][i + 1][j]);
// if (i == 2) {
// cout << f[0][i + 1][j].k << " " << f[0][i + 1][j].b << " " << f[0][i + 1][j].y << endl;
// }
// int t = d;
// ans += work(f[flag][i + 2][x], z * 2 + 1);
// x = ((x - ((1 << (k - i - 1)) - 1)) % d + d) % d;
// if (x == 1 % d) ans += (zhk) {0, z, 1};
f[0][i][(j + (1 << (k - i)) - 1) % d] += rs(f[0][i + 1][j]);
// if (i == 2) {
// cout << rs(f[0][i + 1][j]).k << " " << rs(f[0][i + 1][j]).b << " " << rs(f[0][i + 1][j]).y << endl;
// }
f[1][i][(j + (1 << (k - i))) % d] += rs(f[1][i + 1][j]);
}
}
// if (i == 3) {
// cout << "! " << f[0][i][0].k << endl;
// }
f[0][i][((1 << (k - i + 1)) - 1) % d] += (zhk) {1, 0, 1};
f[1][i][((1 << (k - i))) % d] += (zhk) {1, 0, 1};
// cout << i << " " << f[0][i][0].y << endl;
}
cout << calc(a % d, (a - 1) / d + m) - calc(a % d, (a - 1) / d) << '\n';
} else {
ll ans = 0;
F(i, 1, m) {
// cout << a << " " << query(a) << endl;
ans += query(a);
a += d;
} cout << ans << '\n';
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 57144kb
input:
3 5 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1
output:
2 2 1 3 3
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 57092kb
input:
4 4 2 1 5 4 4 3 4 8 1 10 3 2
output:
18 15 5 13
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 8ms
memory: 57024kb
input:
7 1 1 1 125
output:
4031
result:
ok single line: '4031'
Test #4:
score: 0
Accepted
time: 3ms
memory: 57024kb
input:
2 1 1 1 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 4ms
memory: 57092kb
input:
3 32 1 5 1 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 2 1 1 2 2 1 2 3 1 3 1 1 3 2 1 4 1 1 4 2 2 5 1 2 1 1 2 1 2 2 1 3 2 1 4 2 2 1 2 2 2 2 3 1 2 3 2 3 5 1 3 1 1 3 1 2 3 1 3 3 2 1 3 2 2 4 5 1 4 1 1 4 1 2 5 5 1
output:
2 2 4 5 8 11 2 3 6 2 5 2 5 2 2 3 6 9 2 5 2 5 1 1 4 7 1 4 3 3 6 3
result:
ok 32 lines
Test #6:
score: 0
Accepted
time: 3ms
memory: 57208kb
input:
4 282 1 13 1 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 3 1 1 3 2 1 3 3 1 3 4 1 3 5 1 4 1 1 4 2 1 4 3 1 4 4 1 5 1 1 5 2 1 5 3 1 6 1 1 6 2 1 6 3 1 7 1 1 7 2 1 8 1 1 8 2 1 9 1 1 9 2 1 10 1 1 10 2 1 11 1 1 11 2 1 12 1 1 ...
output:
4 4 8 10 15 20 22 23 26 32 38 41 48 55 4 6 11 12 18 21 28 4 9 10 16 23 4 9 15 22 4 6 9 4 5 12 4 7 4 10 4 10 4 7 4 11 4 11 4 4 6 11 16 18 19 22 28 34 37 44 51 4 9 11 14 20 27 4 9 12 15 4 6 12 4 5 12 4 7 4 10 4 10 4 7 4 11 4 11 2 2 7 12 14 15 18 24 30 33 40 47 2 7 8 14 17 24 2 4 10 17 2 3 6 2 5 12 2 8...
result:
ok 282 lines
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 57092kb
input:
5 268 26 16 1 10 26 1 13 22 1 3 6 2 19 3 4 20 15 1 25 5 1 15 10 1 1 23 2 13 19 1 8 1 8 20 22 1 9 18 1 27 21 1 8 11 2 23 14 1 25 10 1 19 9 2 15 21 1 9 5 2 11 25 1 12 16 2 11 8 3 15 6 1 9 25 1 20 19 1 2 15 1 28 18 1 7 4 1 4 24 2 12 2 7 20 1 5 7 3 5 26 3 2 16 3 4 15 1 7 6 1 3 2 1 25 12 2 6 4 2 12 21 1 ...
output:
14 5 5 14 41 13 14 1 15 5 55 13 10 7 16 3 14 21 1 12 11 26 24 1 10 13 8 15 2 24 54 42 21 29 29 62 16 194 47 96 57 166 95 89 171 125 21 21 122 76 36 112 44 9 71 104 87 18 96 32 21 12 133 89 98 15 19 56 26 52 14 27 46 34 51 47 5 36 39 72 28 65 25 42 29 14 35 33 41 16 56 18 17 17 22 72 18 32 32 113 46 ...
result:
wrong answer 36th lines differ - expected: '60', found: '62'