QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#787427 | #9543. Good Partitions | Hans | WA | 551ms | 40960kb | C++23 | 2.3kb | 2024-11-27 11:40:09 | 2024-11-27 11:40:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// Store factors of n aside from 1 and n itself
vector<int> factors[200001];
void solve() {
int n, q; cin >> n >> q;
// Stores index where ai > a(i+1)
unordered_set<int> s;
// Stores counter of factors
unordered_map<int, int> f;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i < n-1; i++) {
if (arr[i] > arr[i+1]) {
s.insert(i+1);
f[i+1]++;
for (int x : factors[i+1]) {
f[x]++;
}
}
}
if (s.size() == 0) {
cout << n << '\n';
} else {
int sizes = 1;
// Get possible sizes
for (int i : factors[*s.begin()]) {
if (f[i] == s.size())
sizes++;
}
if (f[*s.begin()] == s.size())
sizes++;
cout << sizes << '\n';
}
int i, x;
while (q--) {
cin >> i >> x;
// cout << "Current arr: ";
// for (int i : arr)
// cout << i << " ";
// cout << endl;
if (s.erase(i-1)) {
f[i-1]--;
for (int x : factors[i-1]) f[x]--;
}
if (s.erase(i)) {
f[i]--;
for(int x : factors[i]) f[x]--;
}
arr[i-1] = x;
if (i != 1 && arr[i-2] > arr[i-1]) {
s.insert(i-1);
f[i-1]++;
for (int x : factors[i-1]) f[x]++;
}
if (i != n && arr[i-1] > arr[i]) {
s.insert(i);
f[i]++;
for (int x : factors[i]) f[x]++;
}
// cout << "New set: ";
// for (auto i : s) cout << i << ' ';
// cout << endl;
if (s.size() == 0) {
cout << n << '\n';
continue;
}
int sizes = 1;
// Get possible sizes
// cout << "Factor counts of " << *s.begin() << endl;
for (int i : factors[*s.begin()]) {
// cout << i << ' ' << f[i] << endl;
if (f[i] == s.size())
sizes++;
}
// cout << *s.begin() << ' ' << f[*s.begin()] << endl;
if (f[*s.begin()] == s.size())
sizes++;
cout << sizes << '\n';
}
}
int main() {
// Initiate factors
for (int i = 2; i <= 450; i++) {
for (int x = pow(i,2); x <= 200000; x++) {
if (x%i == 0) {
factors[x].push_back(i);
if (i != x/i)
factors[x].push_back(x/i);
}
}
}
int t; cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 128ms
memory: 23444kb
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: 131ms
memory: 23528kb
input:
1 1 1 2000000000 1 1999999999
output:
1 1
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 496ms
memory: 24312kb
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 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160 200000 160...
result:
ok 200001 lines
Test #4:
score: 0
Accepted
time: 551ms
memory: 40960kb
input:
1 200000 200000 200001 200000 199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199970 199969 199968 199967 199966 199965 199964 199963 199962 1999...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 200001 lines
Test #5:
score: 0
Accepted
time: 323ms
memory: 24288kb
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:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 200001 lines
Test #6:
score: -100
Wrong Answer
time: 131ms
memory: 23496kb
input:
2 2 2 17017 63462 2 94054 2 13504 8 8 14380 5840 34752 73602 60279 26105 44308 78318 7 8597 2 70671 6 56663 5 90093 5 96853 3 10700 1 76875 6 27325
output:
2 2 2 1 1 1 1 1 1 1 1 1
result:
wrong answer 3rd lines differ - expected: '1', found: '2'