QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#587290#9250. Max GCDShiinaMahiruWA 547ms239300kbC++202.8kb2024-09-24 19:09:372024-09-24 19:09:41

Judging History

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

  • [2024-09-24 19:09:41]
  • 评测
  • 测评结果:WA
  • 用时:547ms
  • 内存:239300kb
  • [2024-09-24 19:09:37]
  • 提交

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]+1);
    sum.resize(id[n]+1);
    for(int i=1; i<=id[n]; ++i)sum[i].resize(R[i] - L[i] + 2);
}

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 < sz-1 && dai[x][sz] - dai[x][sz-1] >= dai[x][sz-1] - dai[x][t[x]+1])++t[x];
        }
        if(dai[x].size() >= 3){
            int sz = dai[x].size()-1;
            if(dai[x][sz] - dai[x][sz-1] >= dai[x][sz-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<=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;

}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5588kb

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: 547ms
memory: 239300kb

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:

1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
1680
...

result:

wrong answer 1st words differ - expected: '997920', found: '1680'