QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#739176 | #9543. Good Partitions | Foedere0 | WA | 542ms | 14164kb | C++20 | 2.6kb | 2024-11-12 21:05:06 | 2024-11-12 21:05:14 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
int s[N], a[N], d[N * 4];
int getd(int x)
{
int res = 0;
for (int i = 1; i <= x / i; i++)
{
if (x % i == 0)
{
res++;
if (i != x / i)
res++;
}
}
// sort(res.begin(), res.end());
return res;
}
void pushdown(int p)
{
if (!d[2 * p] && !d[2 * p + 1])
{
d[p] = 0;
}
else if (d[2 * p] && !d[2 * p + 1])
{
d[p] = d[2 * p];
}
else if (!d[2 * p] && d[2 * p + 1])
{
d[p] = d[p * 2 + 1];
}
else
{
d[p] = __gcd(d[p * 2], d[p * 2 + 1]);
}
}
void build(int s, int t, int p)
{
// cout << s << " " << t << " " << p << endl;
if (s == t)
{
// cout << p << " " << a[s] << endl;
d[p] = a[s];
return;
}
int mid = (s + t) >> 1;
build(s, mid, p * 2), build(mid + 1, t, p * 2 + 1);
pushdown(p);
}
void chenge(int s, int t, int e, int c, int p)
{
if (s == t)
{
d[p] = c;
return;
}
int mid = (s + t) >> 1;
if (mid >= e)
chenge(s, mid, e, c, p * 2);
else
chenge(mid + 1, t, e, c, p * 2 + 1);
pushdown(p);
}
void solve()
{
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> s[i];
a[i] = 0;
}
s[n + 1] = 5e9;
for (int i = 1; i <= n; i++)
{
if (s[i] > s[i + 1])
a[i] = i;
}
// cout << endl;
build(1, n, 1);
// cout << d[4] << " **" << d[1] << endl;
int t = d[1];
if (t == 0)
t = n;
cout << getd(t) << endl;
// cout << t << endl;
while (q--)
{
int p, v;
cin >> p >> v;
if (s[p] > s[p + 1] && v <= s[p + 1])
{
chenge(1, n, p, 0, 1);
}
if (s[p] <= s[p + 1] && v > s[p + 1])
{
chenge(1, n, p, p, 1);
}
if (s[p - 1] > s[p] && s[p - 1] <= v && p >= 2)
{
chenge(1, n, p - 1, 0, 1);
}
if (s[p - 1] <= s[p] && s[p - 1] > v && p >= 2)
{
chenge(1, n, p - 1, p - 1, 1);
}
s[p] = v;
int t = d[1];
if (t == 0)
t = n;
// cout << " " << t << endl;
cout << getd(t) << endl;
}
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7736kb
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: 1ms
memory: 7752kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 542ms
memory: 14164kb
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 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42 160 42...
result:
wrong answer 2nd lines differ - expected: '200000', found: '42'