QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552768 | #9250. Max GCD | ucup-team180# | WA | 1305ms | 808476kb | C++20 | 4.0kb | 2024-09-08 02:07:45 | 2024-09-08 02:07:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov3(a, b, c, name, ...) name
#define rep0(n) for(ll aaaaa = 0; aaaaa < n; ++aaaaa)
#define rep1(i, n) for(ll i = 0; i < (n); i++)
#define rep2(i, a, b) for(ll i = (a); i < (b); i++)
#define rep(...) ov3(__VA_ARGS__, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a) - 1; i >= b; i--)
#define fore(e, v) for(auto &&e : v)
#define all(a) begin(a), end(a)
#define si(a) (int)(size(a))
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
#define pb push_back
#define eb emplace_back
#define i128 __int128_t
const ll inf = LLONG_MAX / 3;
template <typename S, S (*op)(S, S), S (*e)()> struct segtree {
segtree(int n) : segtree(vector<S>(n, e())) {}
segtree(const vector<S> &v) : n(si(v)) {
s = bit_ceil(unsigned(n));
log = countr_zero(unsigned(s));
d = vector<S>(2 * s, e());
rep(i, n) d[s + i] = v[i];
per(i, s, 1) update(i);
}
void set(int p, S x) {
d[p += s] = x;
rep(i, 1, log + 1) update(p >> i);
}
S prod(int l, int r) const {
S sml = e(), smr = e();
l += s, r += s;
while(l < r) {
if(l & 1) sml = op(sml, d[l++]);
if(r & 1) smr = op(d[--r], smr);
l >>= 1, r >>= 1;
}
return op(sml, smr);
}
S all_prod() const { return d[1]; }
private:
int n, s, log;
vector<S> d;
void update(int k) { d[k] = op(d[k * 2], d[k * 2 + 1]); }
};
ll f(ll x, ll y) { return max(x, y); }
ll e() { return -inf; }
struct backet {
const ll B = 300;
vl a;
vl b;
void init(ll n) {
a.resize(n);
b.resize(n);
rep(i, n) {
a[i] = 0;
b[i] = 0;
}
}
void set(ll i, ll x) {
// chmax
if(a[i] >= x) return;
a[i] = x;
chmax(b[i / B], x);
}
ll prod(ll r) {
r--;
ll j = r / B;
ll res = -inf;
rep(i, j) chmax(res, b[i]);
for(ll i = j * B; i <= r; i++) { chmax(res, a[i]); }
return res;
}
};
#include <bits/extc++.h>
struct chash {
const uint64_t C = (ll)(4e18 * acos(0)) | 71;
ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};
using namespace __gnu_pbds;
template <class T, class S> using hash_map = gp_hash_table<T, S, chash>;
// #define eb emplace_back
int main() {
cin.tie(0)->sync_with_stdio(0);
ll n, q;
cin >> n >> q;
const ll m = 1e6 + 1;
vl a(n);
vector<vi> G(m);
vector<vector<pii>> mem(n);
rep(i, n) {
cin >> a[i];
for(ll x = 1; x * x <= a[i]; x++)
if(a[i] % x == 0) {
ll y = a[i] / x;
mem[i].eb(x, si(G[x]));
G[x].eb(i);
if(x != y) {
mem[i].eb(y, si(G[y]));
G[y].eb(i);
}
}
}
vector<vector<pii>> ks(n);
rep(g, 1, m) {
if(empty(G[g])) continue;
int j = 0;
rep(i, si(G[g]) - 1) {
while(j < si(G[g]) and G[g][j] - G[g][i + 1] < G[g][i + 1] - G[g][i]) j++;
if(j < si(G[g])) { ks[G[g][i]].eb(g, G[g][j]); }
}
}
vl l(q), r(q);
rep(i, q) {
cin >> l[i] >> r[i];
l[i]--;
}
vector<vl> qs(n);
rep(i, q) { qs[l[i]].pb(i); }
// segtree<ll, f, e> seg(n);
backet bc;
bc.init(n);
vl ans(q);
for(ll i = n - 1; i >= 0; i--) {
for(auto &&[g, k] : ks[i]) { bc.set(k, g); }
fore(j, qs[i]) { ans[j] = bc.prod(r[j]); }
}
rep(i, q) { cout << ans[i] << "\n"; }
// rep(i,n){
// for(auto &&[g,k] : ks[i]){
// ll j = js[i][g];
// cout<<i<<" "<<j<<" "<<k<<" "<<g<<endl;
// }
// }
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 26612kb
input:
8 8 8 24 4 6 6 7 3 3 1 5 2 6 3 7 5 8 4 8 1 3 2 5 3 8
output:
4 2 3 1 3 4 2 3
result:
ok 8 tokens
Test #2:
score: -100
Wrong Answer
time: 1305ms
memory: 808476kb
input:
150000 100000 982800 554400 665280 982800 997920 720720 786240 831600 997920 982800 786240 982800 942480 831600 887040 665280 831600 960960 786240 982800 786240 942480 665280 831600 942480 665280 982800 960960 960960 997920 720720 960960 960960 665280 982800 665280 982800 942480 786240 997920 554400...
output:
997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920 997920...
result:
wrong answer 5108th words differ - expected: '997920', found: '982800'