QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718795 | #9250. Max GCD | leafmaple# | WA | 1766ms | 610192kb | C++20 | 1.4kb | 2024-11-06 21:27:48 | 2024-11-06 21:27:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6+5;
vector<int>g[N];
vector<pair<int,int>>fk[N], ask[N];
int a[N], ans[N];
int tr[N];
void add(int x, int y){
for(;x; x-=(x&-x)){
tr[x] = max(tr[x], y);
}
}
int cal(int x){
int y = -1;
for(;x<=200000; x+=(x&-x)){
y = max(y, tr[x]);
}
return y;
}
signed main (){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(tr, -1, sizeof(tr));
int n, q; cin >> n >> q;
vector<int>fac;
for(int i=1; i<=n; i++){
cin >> a[i];
for(int j = 1; j*j <= a[i]; j++)if(a[i]%j == 0){
g[j].push_back(i);
if(j*j != a[i]) g[a[i]/j].push_back(i);
}
}
const int M = 1e6;
for(int i=1; i<=M; i++)if(g[i].size() >= 3){
int pos = 2;
for(int j = 0; j+2 < g[i].size(); j++){
pos = max(pos, j+2);
int l = g[i][j];
int m = g[i][j+1];
while(g[i][pos] - m < m - l){
pos++;
if(pos >= g[i].size())break;
}
if(pos >= g[i].size())break;
int r = g[i][pos];
fk[r].push_back({l, i});
}
}
for(int i=1; i<=q; i++){
int l, r; cin >> l >> r;
ask[r].push_back({l, i});
}
for(int i=1; i<=n; i++){
for(auto [pos, val]: fk[i]){
add(pos, val);
}
for(auto [pos, id]: ask[i]){
ans[id] = cal(pos);
}
}
for(int i=1; i<=n; i++) cout << ans[i] << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 11496kb
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: 1766ms
memory: 610192kb
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 1518th words differ - expected: '0', found: '-1'