QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548432 | #6405. Barkley | pandapythoner# | WA | 2ms | 3880kb | C++23 | 1.6kb | 2024-09-05 18:25:06 | 2024-09-05 18:25:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define len(a) int((a).size())
#define all(a) begin(a), end(a)
#define rep(i, n) for (int i = 0; i < (n); i++)
int n, q;
vector<ll> a(n);
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> q;
a.resize(n);
rep(i, n) cin >> a[i];
vector<vector<pair<int, ll>>> stck(n + 1);
stck[n] = {};
for (int i = n - 1; i >= 0; i -= 1) {
ll last = a[i];
stck[i].push_back(make_pair(i, a[i]));
for (auto [pos, x] : stck[i + 1]) {
ll val = gcd(last, x);
if (val != last) {
stck[i].push_back(make_pair(pos, val));
last = val;
}
}
}
function<ll(int, int, int)> get;
get = [&](int l, int r, int k) -> ll {
if (k == r - l + 1) return 0;
assert(0 <= k and k < r - l + 1);
if (k == 0) {
auto it = upper_bound(all(stck[l]), make_pair(r, ll(1e18 + 10)));
assert(it != stck[l].begin());
return prev(it)->second;
}
ll last_val = 0;
ll result = 0;
for (auto [pos, g] : stck[l]) {
if (pos + k - 1 > r) break;
result = max(result, gcd(last_val, get(pos + 1, r, k - 1)));
last_val = g;
}
return result;
};
rep(itr, q) {
int l, r, k;
cin >> l >> r >> k; --l; --r;
ll rs = get(l, r, k);
cout << rs << "\n";
}
return 0;
}
/*
4 4
3 2 6 4
1 3 1
2 4 1
1 4 2
1 4 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
4 4 3 2 6 4 1 3 1 2 4 1 1 4 2 1 4 3
output:
3 2 3 6
result:
ok 4 number(s): "3 2 3 6"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3880kb
input:
100 10000 7 25 33 17 13 33 24 29 11 1 3 19 2 20 33 23 14 24 15 12 3 1 5 13 6 35 15 21 10 34 31 19 7 33 17 26 26 1 19 21 31 5 29 20 18 32 19 18 19 31 11 26 6 19 2 26 23 1 4 2 31 21 29 30 1 14 20 23 14 32 4 34 13 29 5 26 24 29 28 5 26 26 21 19 2 33 2 31 30 3 23 24 26 32 36 21 21 11 5 9 56 57 1 90 97 1...
output:
26 1 1 1 1 1 1 1 31 1 1 1 1 1 26 1 1 1 1 1 1 29 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 21 1 1 1 1 1 19 1 1 1 21 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 3 1 2 1 26 1 1 1 1 1 1 1 7 1 1 1 33 1 1 1 1 1 1 2 1 26 1 1 1 2 1 1 1 1 1 1 26 1 1 1 1 31 1 1 2 1 4 29 1 2 1 1...
result:
wrong answer 7823rd numbers differ - expected: '2', found: '1'