ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214298 | #3851. 多项式乘法 | Anthonyyan | 60 | 168ms | 4256kb | C++ | 2.0kb | 2024-11-17 09:59:49 | 2024-11-17 13:05:56 |
answer
#include <bits/stdc++.h>
#define int long long
#define lowbit(x) ((x) & (-x))
#define rep(i, s, t, st) for (int i = s, __##i = t; i <= __##i; i += st)
#define per(i, s, t, st) for (int i = s, __##i = t; i >= __##i; i -= st)
#define gc getchar
#define lc(x) ((x) << 1)
#define rc(x) (((x) << 1) | 1)
#define pll pair<int, int>
#define clr(pst, siz) memset(pst, 0, sizeof(int) * siz)
#define cpy(pst, tar, siz) memcpy(pst, tar, sizeof(int) * siz)
inline int read()
{
int x = 0, f = 1, ch = gc();
while (!isdigit(ch))
{
if (ch == '-')
f = -f;
ch = gc();
}
while (isdigit(ch))
{
x = (x << 1) + (x << 3) + ch - '0';
ch = gc();
}
return x * f;
}
inline void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x / 10)
write(x / 10);
putchar('0' + x % 10);
}
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXM = 2e5 + 10;
const int MAXQ = 2e5 + 10;
int n, m, q, c, d;
int a[MAXN], b[MAXN];
int g, tx, ty;
void extGcd(int a, int b, int &d, int &x, int &y)
{
if (!b)
d = a, x = 1, y = 0;
else
{
extGcd(b, a % b, d, y, x);
y -= x * (a / b);
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("multi.in", "r", stdin);
freopen("multi.out", "w", stdout);
#endif
n = read(), m = read(), q = read();
rep(i, 0, n, 1)
a[i] = read();
rep(i, 0, n, 1)
b[i] = read();
while (q--)
{
c = read(), d = read();
int ans = 0;
extGcd(c, d, g, tx, ty);
if (m % g)
{
puts("0");
continue;
}
tx *= m / g, ty *= m / g;
int sx = d / g, sy = c / g;
int t_min = ceil(-1.0 * tx / sx);
int t_max = floor(1.0 * ty / sy);
bool flag = false;
rep(t, t_min, t_max, 1)
{
int x = tx + sx * t;
int y = ty - sy * t;
if (x >= 0 && y >= 0)
{
ans += a[x] * b[y];
flag = true;
}
}
write(ans), puts("");
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1152kb
input:
999 996 1000 181 806 745 589 721 351 654 278 172 787 785 328 876 63 436 237 822 649 932 55 332 99 13...
output:
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 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000 tokens
Test #2:
score: 10
Accepted
time: 1ms
memory: 1152kb
input:
999 999 998 629 817 295 274 803 741 680 334 314 300 960 880 958 153 650 621 830 812 753 954 925 128 ...
output:
0 0 0 0 0 573534 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 0 0...
result:
ok 998 tokens
Test #3:
score: 10
Accepted
time: 0ms
memory: 1148kb
input:
999 1000 996 405 332 85 45 221 452 98 110 660 639 88 132 660 917 688 160 46 739 398 344 813 746 593 ...
output:
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 87480 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 996 tokens
Test #4:
score: 10
Accepted
time: 1ms
memory: 1152kb
input:
1000 998 998 166 218 178 246 965 67 723 748 446 558 450 939 19 72 123 256 942 873 269 573 991 463 68...
output:
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 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 998 tokens
Test #5:
score: 10
Accepted
time: 83ms
memory: 4252kb
input:
199997 199999 199998 1302 180172 139335 170014 31751 7467 183386 71639 67797 140829 155107 61564 984...
output:
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 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 199998 tokens
Test #6:
score: 10
Accepted
time: 83ms
memory: 4256kb
input:
199997 199997 200000 84501 46291 64694 156236 116548 147672 10286 54151 157755 190434 70365 145475 1...
output:
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 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 200000 tokens
Test #7:
score: 0
Time Limit Exceeded
input:
200000 199996 199997 10072 125769 117200 152038 170661 109407 73931 21884 144280 181053 47148 44210 ...
output:
334685832754280 2006121597481107 2006121597481107 334685832754280 1003645394194469 1003985461234743 ...
result:
Test #8:
score: 0
Time Limit Exceeded
input:
200000 200000 200000 94005 71739 112951 57403 31797 74173 113981 44673 166545 101677 135207 32182 50...
output:
331980465051390 665207656334083 331980465051390 667144879609525 995955892733627 665207656334083 6671...
result:
Test #9:
score: 0
Time Limit Exceeded
input:
199997 199998 199997 114782 89426 5154 72561 99785 66889 106549 2708 46310 108849 58268 188339 12902...
output:
668064176928395 1006036966789885 1002037134949456 2007398588671654 332516419084262 1006036966789885 ...
result:
Test #10:
score: 0
Time Limit Exceeded
input:
199998 199997 199997 194270 184004 139383 148257 117737 8328 66533 187509 47247 118806 176038 42976 ...
output:
1999294464955238 1999294464955238 0 329637326523124 1000882324376412 0 666546849218999 6665468492189...