QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637810 | #9250. Max GCD | ucup-team4479# | WA | 2127ms | 1008212kb | C++23 | 2.6kb | 2024-10-13 14:08:59 | 2024-10-13 14:08:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=150005;
const int M=1000005;
int n,q;
int a[N];
struct Segment_Tree
{
#define ls i*2
#define rs i*2+1
struct Node
{
int l,r;
int mx;
}tree[N*4];
void push_up(int i)
{
tree[i].mx=max(tree[ls].mx,tree[rs].mx);
return;
}
void build(int i,int l,int r)
{
tree[i].l=l,tree[i].r=r;
if(l==r)
{
tree[i].mx=1;
return;
}
int mid=(l+r)>>1;
build(ls,l,mid);
build(rs,mid+1,r);
push_up(i);
return;
}
void modify(int i,int u,int v)
{
if(tree[i].l==tree[i].r)
{
tree[i].mx=max(tree[i].mx,v);
return;
}
if(u<=tree[ls].r) modify(ls,u,v);
else modify(rs,u,v);
push_up(i);
return;
}
int query(int i,int ql,int qr)
{
if(ql<=tree[i].l&&tree[i].r<=qr) return tree[i].mx;
int res=0;
if(ql<=tree[ls].r) res=max(res,query(ls,ql,qr));
if(qr>=tree[rs].l) res=max(res,query(rs,ql,qr));
return res;
}
}T;
int lst[M];
vector<pair<int,int>>seg[N];
vector<pair<int,int>>query[N];
vector<tuple<int,int,int>>pos[N];
int ans[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int j=1;j<=n;j++)
{
auto calc=[&](int g)
{
if(g==1) return;
int i=lst[g];
if(i==0) return;
if(j+j-i<=n) pos[j+j-i].emplace_back(i,j,g);
return;
};
for(int g=1;g*g<=a[j];g++)
if(a[j]%g==0)
{
calc(g);
if(g*g!=a[j]) calc(a[j]/g);
}
for(int g=1;g*g<=a[j];g++)
if(a[j]%g==0) lst[g]=lst[a[j]/g]=j;
}
memset(lst,0,sizeof(lst));
for(int l=n;l>=1;l--)
{
for(int g=1;g*g<=a[l];g++)
if(a[l]%g==0) lst[g]=lst[a[l]/g]=l;
for(auto [i,j,g]:pos[l])
{
int k=lst[g];
if(k==0) continue;
seg[k].emplace_back(i,g);
}
}
for(int i=1;i<=q;i++)
{
int l,r;
cin>>l>>r;
query[r].emplace_back(l,i);
}
T.build(1,1,n);
for(int r=1;r<=n;r++)
{
for(auto &[i,g]:seg[r])
T.modify(1,i,g);
for(auto &[l,id]:query[r])
ans[id]=T.query(1,l,r);
}
for(int i=1;i<=q;i++)
cout<<ans[i]<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7660kb
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: 2127ms
memory: 1008212kb
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'