QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#587534#9250. Max GCDShiinaMahiruWA 1112ms582220kbC++172.8kb2024-09-24 20:33:592024-09-24 20:33:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 20:33:59]
  • 评测
  • 测评结果:WA
  • 用时:1112ms
  • 内存:582220kb
  • [2024-09-24 20:33:59]
  • 提交

answer

// #pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
#define lowbits(x) ((x)&((-x)))
#define INF 0x3f3f3f3f
#define uu __int128
#define PI acos(-1)
#define ls k<<1
#define rs k<<1|1
using namespace std;
typedef  long long ll;
typedef  unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PII;
constexpr int N=150000+10, M=1e6+10;
constexpr int mod=998244353;
constexpr double eps=1e-9;
int nx[] = {0, 0, 1, -1}, ny[] = {1, -1, 0, 0};


int n,m;
int a[N];
vector<int> dai[M];
int t[M];
vector<P> g[N], q[N];
constexpr int B = 300;
int id[N], L[N], R[N];
vector<int> SUM;
vector<vector<int>> sum;
void init(){
    for(int i=1; i<=n; ++i){
        id[i] = (i-1) / B + 1;
    }
    for(int i=1; i<=id[n]; ++i){
        L[i] = (i-1) * B + 1;
        R[i] = min(n, i * B);
    }
    SUM.resize(id[n]+10);
    sum.resize(id[n]+10);
    for(int i=0; i<=id[n]; ++i)sum[i].resize(R[i] - L[i] + 10);
}

void update(int y, int w){
    sum[id[y]][y - L[id[y]] + 1] = max(sum[id[y]][y - L[id[y]] + 1], w);
    SUM[id[y]] = max(SUM[id[y]], w);
}

int query(int x){
    int res = 0;
    for(int i=1; i<id[x]; ++i)res = max(res, SUM[i]);
    for(int i=L[id[x]]; i<=x; ++i)res = max(res, sum[id[x]][i - L[id[x]] + 1]);
    return res;
}


void solve(){
    cin >> n >> m;
    init();
    auto add = [&](int x, int pos){
        dai[x].push_back(pos);
        if(dai[x].size() >= 3){
            int sz = dai[x].size()-1;
            while(t[x]+1+1 < sz && dai[x][sz] - dai[x][t[x]+2] >= dai[x][t[x]+2] - dai[x][t[x]+1])++t[x];
            if(t[x]+1 < sz && dai[x][sz] - dai[x][t[x]+1] >= dai[x][t[x]+1] - dai[x][t[x]]){
                g[dai[x][t[x]]].push_back({dai[x][sz], x});
            }
        }
    };
    for(int i=1; i<=n; ++i){
        cin >> a[i];
        for(int j=1; j*j<=a[i]; ++j){
            if(a[i] % j == 0){
                int k = a[i] / j;
                add(j, i);
                if(j != k)
                add(k, i);
            }
        }
    }
    for(int i=1; i<M; ++i)dai[i].clear();
    // for(int i=1; i<=n; ++i){
    //     if(g[i].size()){
    //         for(auto [y, w] : g[i])cout << i << ' ' << y << ' ' << w << endl;
    //     }
    // }
    for(int i=1; i<=m; ++i){
        int l,r;
        cin >> l >> r;
        q[l].push_back({r, i});
    }
    vector<int> res(m+1);
    for(int i=n; i>=1; --i){
        for(auto [y, w] : g[i]){
            update(y, w);
        }
        for(auto [r, id] : q[i]){
            res[id] = query(r);
        }
    }
    for(int i=1; i<=m; ++i)cout << res[i] << endl;



}


signed main()
{   
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    int t = 1;
    // cout << fixed << setprecision(9)
    // cin >> t;
    while(t--)solve();
    return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 36444kb

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: 1112ms
memory: 582220kb

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'