QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108209#6405. BarkleywsyearWA 7ms5380kbC++172.2kb2023-05-23 21:33:422023-05-23 21:35:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 21:35:52]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:5380kb
  • [2023-05-23 21:33:42]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define gc getchar
#define pc putchar
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

template <class T = int> T read() {
  T x = 0; bool f = 0; char ch = gc();
  while (!isdigit(ch)) f = ch == '-', ch = gc();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = gc();
  return f ? -x: x;
}
template <class T> void write(T x) {
  if (x >= 0) { if (x > 9) write(x / 10); pc(x % 10 + 48); }
  else { pc('-'); if (x < -9) write(-x / 10); pc(48 - x % 10); }
}

const int N = 100010;

int n, q;
ll a[N], st[N][21], ans;

ll qry(int l, int r) {
  int k = __lg(r - l + 1);
  return gcd(st[l][k], st[r - (1 << k) + 1][k]);
}

bool check(int l, int r, ll d) {
  int k = __lg(r - l + 1);
  return (st[l][k] % d == 0) && (st[r - (1 << k) + 1][k] % d == 0);
}

void solve(int l, int r, int k, ll d) {
  if (k == 0 && l > r) return ans = max(ans, d), void();
  if (r - l + 1 < k) return;
  if (k == 0) {
    d = gcd(d, qry(l, r));
    return ans = max(ans, d), void();
  }
  solve(l + 1, r, k - 1, d), d = gcd(d, a[l]);
  for (int x = l, y; x <= r; x = y + 2) {
    y = x;
    per (i, 20, 0) {
      if (y + (1 << i) > r) continue;
      if (!check(x, y + (1 << i), d)) continue;
      y += (1 << i);
    }
    solve(y + 1, r, k, d);
    d = gcd(d, a[y + 1]);
  }
}

int main() {
  n = read(), q = read();
  rep (i, 1, n) a[i] = read<ll>();
  rep (i, 1, n) st[i][0] = a[i];
  rep (j, 1, 20) rep (i, 1, n - (1 << j) + 1)
    st[i][j] = gcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  while (q--) {
    int l = read(), r = read(), k = read();
    ans = 0, solve(l, r, k, 0);
    write(ans), pc(10);
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4
3 2 6 4
1 3 1
2 4 1
1 4 2
1 4 3

output:

3
2
3
6

result:

ok 4 number(s): "3 2 3 6"

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 5380kb

input:

100 10000
7 25 33 17 13 33 24 29 11 1 3 19 2 20 33 23 14 24 15 12 3 1 5 13 6 35 15 21 10 34 31 19 7 33 17 26 26 1 19 21 31 5 29 20 18 32 19 18 19 31 11 26 6 19 2 26 23 1 4 2 31 21 29 30 1 14 20 23 14 32 4 34 13 29 5 26 24 29 28 5 26 26 21 19 2 33 2 31 30 3 23 24 26 32 36 21 21 11 5 9
56 57 1
90 97 1...

output:

26
1
1
1
1
1
1
1
31
3
1
1
1
1
26
1
1
1
1
1
1
29
1
1
1
1
1
1
4
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
4
1
1
1
21
1
1
3
1
1
19
1
1
1
21
1
1
1
1
1
2
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
1
1
1
4
2
1
1
1
1
3
1
2
1
26
1
1
1
1
1
1
1
7
1
1
1
33
1
1
1
1
2
1
2
1
26
1
1
1
2
1
1
1
1
1
1
26
1
1
1
1
31
1
1
2
1
4
29
1
2
1
1...

result:

wrong answer 10th numbers differ - expected: '1', found: '3'