/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Time Exceeded ≥2599ms ≥15.773 MiB
#2 Time Exceeded ≥2597ms ≥15.77 MiB

Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int const N = 1e6 + 2;
vector<ll> a(N);

class SegmentTree {
  public:
  ll n;
  vector<ll> tree;
  SegmentTree(ll n) : tree(2 * n + 10), n(n){};

  void build() {
    for (int i = 1; i <= n; i++) 
      tree[n + i] = a[i];
    for (int i = n; i > 0; i--) 
      tree[i] = max(tree[i << 1], tree[i << 1 | 1]);
  }

  ll query(int l, int r) {
    ll res = 0;
    for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res = max(res, tree[l++]);
      if (r & 1) res = max(res, tree[--r]);
    }
    return res;
  }
};



int main() {
  vector<ll> d(N);
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) {
      d[j]++;
    }
  }
  ll S = 0;
  for (int i = 1; i < N - 1; i++) {
    S += i; 
    if (S < N - 1) a[i] = d[S];
    else {
      ll c = 0;
      for (ll j = 1; j * j <= S; j++) {
        if (S % j == 0) {
          c++;
          if (S / j != j) c++;
        }
      }
      a[i] = c;
    }
  }
  SegmentTree mx(N - 1);
  mx.build();
  int t;
  cin >> t;
  while (t--){
    ll n;
    cin >> n;
    cout << mx.query(1, n) << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 17:40:17
Judged At
2025-04-06 17:40:17
Judged By
Score
0
Total Time
≥2599ms
Peak Memory
≥15.773 MiB