QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607616#9250. Max GCDpropane#WA 2310ms499736kbC++203.5kb2024-10-03 15:33:402024-10-03 15:33:41

Judging History

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

  • [2024-10-03 15:33:41]
  • 评测
  • 测评结果:WA
  • 用时:2310ms
  • 内存:499736kb
  • [2024-10-03 15:33:40]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<array>
using namespace std;
using LL = long long;

#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<functional>
using namespace std;

struct Info {
    int mx = 0;
};

Info operator+(const Info &a, const Info &b){
    return {max(a.mx, b.mx)};
}

template<class Info>
struct SegmentTree{
    int n;
    vector<Info> info;

    SegmentTree() {}

    SegmentTree(int n, Info _init = Info()){
        init(vector<Info>(n, _init));
    }

    SegmentTree(const vector<Info> &_init){
        init(_init);
    }

    void init(const vector<Info> &_init){
        n = (int)_init.size();
        info.assign((n << 2) + 1, Info());
        function<void(int, int, int)> build = [&](int p, int l, int r){
            if (l == r){
                info[p] = _init[l - 1];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m + 1, r);
            pull(p);
        };
        build(1, 1, n);
    }

    void pull(int p){
        info[p] = info[2 * p] + info[2 * p + 1];
    }

    void modify(int p, int l, int r, int x, const Info &v){
        if (l == r){
            info[p] = info[p] + v;
            return;
        }
        int m = (l + r) / 2;
        if (x <= m){
            modify(2 * p, l, m, x, v);
        } 
        else{
            modify(2 * p + 1, m + 1, r, x, v);
        }
        pull(p);
    }

    void modify(int p, const Info &v){
        modify(1, 1, n, p, v);
    }

    Info query(int p, int l, int r, int x, int y){
        if (l > y || r < x){
            return Info();
        }
        if (l >= x && r <= y){
            return info[p];
        }
        int m = (l + r) / 2;
        return query(2 * p, l, m, x, y) + query(2 * p + 1, m + 1, r, x, y);
    }

    Info query(int l, int r){
        return query(1, 1, n, l, r);
    }
};

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    const int N = 1e6;
    int n, m;
    cin >> n >> m;
    vector<vector<int> > pos(N + 1);
    for(int i = 1; i <= n; i++){
        int t;
        cin >> t;
        for(int j = 1; j * j <= t; j++){
            if (t % j == 0){
                pos[j].push_back(i);
                if (j * j != t){
                    pos[t / j].push_back(i);
                }
            }
        }
    }
    vector<vector<pair<int, int> > > seg(n + 1);
    for(int i = 1; i <= N; i++){
        if (!pos[i].empty()){
            for(int j = 0, k = 0; j + 1 < pos[i].size(); j++){
                int a = pos[i][j], b = pos[i][j + 1];
                while(k < pos[i].size() and pos[i][k] - b < b - a) k++;
                if (k == pos[i].size()) break;
                seg[a].push_back({pos[i][k], i});
            }
        }
    }
    vector<vector<pair<int, int> > > query(n + 1);
    vector<int> ans(m);
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        query[l].push_back({r, i});
    }
    SegmentTree<Info> st(n);
    for(int i = n; i >= 1; i--){
        for(auto [r, val] : seg[i]){
            st.modify(r, {val});
        }
        for(auto [r, id] : query[i]){
            ans[id] = st.query(i, r).mx;
        }
    }
    for(auto x : ans) cout << x << '\n';

}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 26644kb

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: 2310ms
memory: 499736kb

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'