QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738233 | #9543. Good Partitions | RWeakest | WA | 82ms | 7832kb | C++20 | 3.1kb | 2024-11-12 18:19:39 | 2024-11-12 18:19:40 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 2e5 + 100;
int ans[MAXN];
int cnt(int x)
{
int num = 1;
for (int i = 2; i * i <= x; ++i)
if (!(x % i))
{
int temp = 0;
while (!(x % i))
x /= i, temp++;
num *= (temp + 1);
}
return x == 1 ? num : num * 2;
}
void get_ans()
{
for (int i = 1; i <= 200000; ++i)
ans[i] = cnt(i);
return;
}
int tree[MAXN << 2], a[MAXN], g[MAXN], n, m;
int ls(int x)
{
return x << 1;
}
int rs(int x)
{
return (x << 1) | 1;
}
int mid(int l, int r)
{
return l + ((r - l) >> 1);
}
void maintain(int x)
{
tree[x] = __gcd(tree[ls(x)], tree[rs(x)]);
}
void build(int l, int r, int x)
{
// cout << "l:" << l << " r:" << r << " x:" << x << "\n";
if (l == r)
{
tree[x] = g[l];
return;
}
int m = mid(l, r);
build(l, m, ls(x)), build(m + 1, r, rs(x));
maintain(x);
}
void modify(int l, int r, int x, int p, int num)
{
if (l == r && l == x)
{
tree[p] = num;
return;
}
if (mid(l, r) >= x)
modify(l, mid(l, r), x, ls(p), num);
if (x > mid(l, r))
modify(mid(l, r) + 1, r, x, rs(p), num);
maintain(p);
}
void init()
{
for (int i = 1; i <= 4 * n; ++i)
tree[i] = 0;
for (int i = 1; i <= n; ++i)
g[i] = 0;
}
void solve()
{
init();
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n - 1; ++i)
if (a[i] > a[i + 1])
g[i] = i;
if (n == 1)
{
for (int i = 1; i <= n + 1; ++i)
{
cout << 1 << "\n";
}
return;
}
// for (int i = 1; i <= n; ++i)
// cout << g[i] << " \n"[i == n];
build(1, n, 1);
cout << ans[tree[1]] << "\n";
while (m--)
{
int x, w;
cin >> x >> w;
a[x] = w;
if (!g[x - 1])
{
if (a[x - 1] > a[x])
{
g[x - 1] = x - 1;
modify(1, n, x - 1, 1, x - 1);
}
}
else
{
if (a[x - 1] <= a[x])
{
g[x - 1] = 0;
modify(1, n, x - 1, 1, 0);
}
}
if (x == n)
{
cout << ans[tree[1]] << '\n';
continue;
}
if (!g[x])
{
if (a[x] > a[x + 1])
{
g[x] = x;
modify(1, n, x, 1, x);
}
}
else
{
if (a[x] <= a[x + 1])
{
g[x] = 0;
modify(1, n, x, 1, 0);
}
}
cout << ans[tree[1]] << '\n';
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
get_ans();
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 43ms
memory: 7832kb
input:
1 5 2 4 3 2 6 1 2 5 3 5
output:
1 2 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 40ms
memory: 6460kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 82ms
memory: 7688kb
input:
1 200000 200000 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 160 0 ...
result:
wrong answer 2nd lines differ - expected: '200000', found: '0'