QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#550804 | #9250. Max GCD | ucup-team4801# | WA | 1877ms | 647540kb | C++14 | 1.2kb | 2024-09-07 14:19:57 | 2024-09-07 14:19:57 |
Judging History
answer
#include<bits/stdc++.h>
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
const int N=1e6+10,V=1e6;
int n,q,a[N],ans[N];
vector<int> G[N],ps[N];
vector<pair<int,int> >qr[N],qs[N];
int t[N];
#define lbt(x) (x&-x)
void add(int x,int k){for(;x<=n;x+=lbt(x)) t[x]=max(t[x],k);}
int ask(int x){int res=1;for(;x;x-=lbt(x)) res=max(res,t[x]);return res;}
int main(){
rep(i,2,V) rep(j,1,V/i) G[i*j].push_back(i);
scanf("%d%d",&n,&q);int l,r,x;rep(i,1,n){scanf("%d",&x);for(int y:G[x]) ps[y].push_back(i);}
rep(x,2,V){
if(ps[x].size()<2) continue;
int j=0;rep(i,0,ps[x].size()-2){
while(j<ps[x].size()&&ps[x][j]-ps[x][i+1]<ps[x][i+1]-ps[x][i]) ++j;
if(j<ps[x].size()&&ps[x][j]-ps[x][i+1]>=ps[x][i+1]-ps[x][i]) qs[ps[x][i]].push_back({ps[x][j],x});
}
}
rep(i,1,q){scanf("%d%d",&l,&r);if(r-l>=2) qr[l].push_back({r,i});}
per(i,n,1){
for(auto I:qs[i]) add(I.first,I.second);
for(auto I:qr[i]) ans[I.second]=ask(I.first);
}
rep(i,1,q) printf("%d\n",ans[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 645ms
memory: 187136kb
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: 1877ms
memory: 647540kb
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'