QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#597148#9250. Max GCDDBsoleil#TL 686ms118132kbC++201.3kb2024-09-28 17:09:412024-09-28 17:09:48

Judging History

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

  • [2024-09-28 17:09:48]
  • 评测
  • 测评结果:TL
  • 用时:686ms
  • 内存:118132kb
  • [2024-09-28 17:09:41]
  • 提交

answer


#include <bits/stdc++.h>
using namespace std;
static constexpr int Maxn = 1.5e5 + 5, V = 1e6, MaxV = 1e6 + 5;
int n, qn, ans[Maxn], a[Maxn];
vector<int> d[MaxV], g[MaxV];
vector<pair<int, int>> p[Maxn], q[Maxn];
int fen[Maxn];
void upd(int x, int y) { for (; x <= n; x += x & -x) fen[x] = max(fen[x], y); }
int ask(int x) { int r = 0; for (; x; x -= x & -x) r = max(r, fen[x]); return r; }
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> n >> qn;
  for (int i = 1; i <= V; ++i)
    for (int j = i; j <= V; j += i) d[j].push_back(i);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) for (int j: d[a[i]]) g[j].push_back(i);
  for (int d = V; d >= 1; --d) {
    for (int i = 0; i < (int)g[d].size() - 2; ++i) {
      int x = g[d][i], y = g[d][i + 1], z = 2 * y - x;
      int w = lower_bound(g[d].begin(), g[d].end(), z) - g[d].begin();
      if (w != (int)g[d].size()) p[x].push_back({g[d][w], d});
    }
  }
  for (int i = 1; i <= qn; ++i) {
    int l, r; cin >> l >> r;
    q[l].push_back({r, i});
  }
  // x >= L, y <= R;
  for (int i = n; i >= 1; --i) {
    for (auto [y, w]: p[i]) upd(y, w);
    for (auto [y, id]: q[i]) ans[id] = ask(y);
  }
  for (int i = 1; i <= qn; ++i)
    printf("%d\n", ans[i]);
  return 0;
} // main

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 686ms
memory: 118132kb

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
Time Limit Exceeded

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:


result: