QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744239 | #9543. Good Partitions | Lonelyper | WA | 100ms | 12232kb | C++20 | 2.8kb | 2024-11-13 21:16:25 | 2024-11-13 21:16:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10, M = 1e6 + 10;
int n, q;
int g[N], a[N], tree[N << 2];
int h[M];
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
void init2(){
for(int i = 1; i < M; i ++){
for(int j = i; j < M; j += i){
h[j] ++;
}
}
}
void init(){
for(int i = 0; i <= n ; i ++) g[i] = 0;
for(int i = 0; i <= 4 * n; i ++) tree[i] = 0;
}
void push_up(int p) {
tree[p] = gcd(tree[p << 1], tree[p << 1 | 1]);
}
void build(int p, int pl, int pr) {
if (pl == pr) {
tree[p] = g[pl];
return;
}
int mid = (pl + pr) >> 1;
build(p << 1, pl, mid);
build(p << 1 | 1, mid + 1, pr);
push_up(p);
}
int query(int l, int r, int p, int pl, int pr) {
if (l <= pl && pr <= r) return tree[p];
int mid = (pl + pr) >> 1;
LL res = 0;
if (l <= mid) res = gcd(res, query(l, r, p << 1, pl, mid));
if (r > mid) res = gcd(res, query(l, r, p << 1 | 1, mid + 1, pr));
return res;
}
void update(int pos) {
if (pos > 1) {
if (a[pos - 1] > a[pos]) g[pos - 1] = pos - 1;
else g[pos - 1] = 0;
}
if (pos < n) {
if (a[pos] > a[pos + 1]) g[pos] = pos;
else g[pos] = 0;
}
}
void update_tree(int pos, int p, int pl, int pr) {
if (pl == pr) {
tree[p] = g[pl];
return;
}
int mid = (pl + pr) >> 1;
if (pos <= mid) update_tree(pos, p << 1, pl, mid);
else update_tree(pos, p << 1 | 1, mid + 1, pr);
push_up(p);
}
void solve() {
cin >> n >> q;
init();
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
if (a[i] > a[i + 1]) g[i] = i;
else g[i] = 0;
}
if(n == 1){
cout << 1 << endl;
for(int i = 1; i <= q; i ++){
int p, x;
cin >> p >> x;
cout << 1 << endl;
}
return;
}
build(1, 1, n - 1);
// cout << tree[1] << ' ';
int x = query(1, n - 1, 1, 1, n - 1);
cout << h[x] << endl;
// cout << h[1] << ' ' << h[2] << ' ' << h[4] << endl;
while (q--) {
int pos, x;
cin >> pos >> x;
a[pos] = x;
if (pos > 1) {
update(pos - 1);
update_tree(pos - 1, 1, 1, n - 1);
}
if (pos < n) {
update(pos);
update_tree(pos, 1, 1, n - 1);
}
// for(int i = 1; i <= n; i ++) cout << g[i] << ' ';
// cout << endl;
// cout << tree[1] << ' ';
x = query(1, n - 1, 1, 1, n - 1);
cout << h[x] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
init2();
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 22ms
memory: 11364kb
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: 23ms
memory: 11368kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 100ms
memory: 12232kb
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'