QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#748258 | #9543. Good Partitions | Yg6189 | WA | 147ms | 11624kb | C++14 | 2.1kb | 2024-11-14 19:50:22 | 2024-11-14 19:50:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define il inline
#define rd read()
#define ls (p << 1)
#define rs (p << 1 | 1)
const int inf = 10e5 + 100, L = 2e5 + 100, mod = 1e9 + 7;
int n, q;
int a[L], s[L << 2];
il int read()
{
int res = 0, f = 1;
char c = getchar();
while(c < '0' || c >'9')
{
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9')
{
res = res * 10 + c - 48;
c = getchar();
}
return res * f;
}
il int gcd(int x, int y)
{
return __gcd(x, y);
}
il void pushUp(int p)
{
s[p] = gcd(s[ls], s[rs]);
}
il void build(int p = 1, int l = 1, int r = n - 1)
{
if(l == r)
{
s[p] = (a[l] > a[l + 1] || l == n) ? l : 0;
return;
}
int mid = (l + r) / 2;
build(ls, l, mid), build(rs, mid + 1, r);
pushUp(p);
}
il void update(int pos, int x, int p = 1, int l = 1, int r = n - 1)
{
if(l == r)
{
s[p] = x; return;
}
int mid = (l + r) / 2;
if(pos <= mid) update(pos, x, ls, l, mid);
else update(pos, x, rs, mid + 1, r);
pushUp(p);
}
signed main() {
// freopen("test.out", "w", stdout);
int t = rd;
while(t --)
{
n = rd, q = rd;
for(int i = 1; i <= n; ++ i) a[i] = rd;
if(n == 1)
{
printf("1\n");
while(q --)
{
int p = rd, x = rd;
printf("1\n");
}
continue;
}
build();
int ans = s[1], num = 0;
for(int i = 1; i * i <= ans; ++ i)
{
if(ans % i == 0)
{
num ++;
if(ans / i != i) num ++;
}
}
printf("%lld\n", num);
int p, x;
while(q --)
{
p = rd, x = rd;
if(p > 1 && a[p] >= a[p - 1] && x < a[p - 1]) update(p - 1, p - 1);
if(p > 1 && a[p] < a[p - 1] && x >= a[p - 1]) update(p - 1, 0);
if(p < n && a[p] <= a[p + 1] && x > a[p + 1]) update(p, p);
if(p < n && a[p] > a[p + 1] && x <= a[p + 1]) update(p, 0);
a[p] = x;
ans = s[1], num = 0;
// cout << "test " << ans << endl;
for(int i = 1; i * i <= ans; ++ i)
{
if(ans % i == 0)
{
num ++;
if(ans / i > i) num ++;
}
}
printf("%lld\n", num);
}
}
return 0;
}
/*
1
5 2
4 3 2 6 1
2 5
3 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5796kb
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: 0ms
memory: 3772kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 147ms
memory: 11624kb
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'