QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769528 | #9543. Good Partitions | Gaze | WA | 272ms | 44136kb | C++14 | 1.9kb | 2024-11-21 18:03:29 | 2024-11-21 18:03:30 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int T, n, q, ans;
int f[200010], d[200010], tr[800010];
vector<int> num[200010];
void build(int l, int r, int p) {
if(l == r) {
if(d[l] < 0) tr[p] = l - 1;
else tr[p] = 0;
return;
}
int mid = (l + r) / 2;
build(l, mid, p * 2);
build(mid + 1, r, p * 2 + 1);
if(tr[p * 2] == 0 || tr[p * 2 + 1] == 0) tr[p] = max(tr[p * 2], tr[p * 2 + 1]);
else tr[p] = __gcd(tr[p * 2], tr[p * 2 + 1]);
}
void update(int l, int r, int x, int p) {
if(l == r) {
if(d[l] < 0) tr[p] = l - 1;
else tr[p] = 0;
return;
}
int mid = (l + r) / 2;
if(x <= mid) update(l, mid, x, p * 2);
else update(mid + 1, r, x, p * 2 + 1);
if(tr[p * 2] == 0 || tr[p * 2 + 1] == 0) tr[p] = max(tr[p * 2], tr[p * 2 + 1]);
else tr[p] = __gcd(tr[p * 2], tr[p * 2 + 1]);
}
void preDeal() {
for(int i = 1; i <= 200000; ++i) {
for(int j = 1; j <= sqrt(i); ++j) {
if(i % j != 0) continue;
if(j * j == i) num[i].push_back(j);
else {
num[i].push_back(j);
num[i].push_back(i / j);
}
}
}
}
void solve() {
for(int i = 1; i <= n; ++i) {
d[i] = f[i] - f[i - 1];
}
build(1, n, 1);
int x, v;
int ans = num[tr[1]].size();
cout << max(ans, (long long)1) << endl;
for(int i = 1; i <= q; ++i) {
x = read();
v = read();
f[x] = v;
d[x] = f[x] - f[x - 1];
d[x + 1] = f[x + 1] - f[x];
update(1, n, x, 1);
if(x + 1 <= n) (1, n, x + 1, 1ll);
ans = num[tr[1]].size();
cout << max(ans, (long long)1) << endl;
}
}
signed main() {
T = read();
preDeal();
while(T) {
T -= 1;
n = read();
q = read();
for(int i = 1; i <= n; ++i) f[i] = read();
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 209ms
memory: 39664kb
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: 213ms
memory: 38676kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 272ms
memory: 44136kb
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 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 160 ...
result:
wrong answer 2nd lines differ - expected: '200000', found: '160'