Submission #467003

# Submission time Handle Problem Language Result Execution time Memory
467003 2021-08-21T08:56:41 Z erray Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
412 ms 23364 KB
// author: erray
#include <bits/stdc++.h>
 
using namespace std;
template<typename A, typename B> string to_string(const pair<A, B>& p);
template<typename A, typename B, typename C> string to_string(const tuple<A, B, C>& t);
template<typename A, typename B, typename C, typename D> string to_string(const tuple<A, B, C, D>& t);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& c) {
  return string("'") + c + "'";
}

string to_string(const char *c) {
  return to_string(string(c));
}

string to_string(const bool& b) {
  return (b ? "true" : "false");
}

string to_string(const vector<bool>& v) {
  string res = "{";
  for (int i = 0; i < (int) v.size(); ++i) {
    if (i > 0) {
      res += ", ";
    }
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template<size_t T> string to_string(const bitset<T>& bs) {
  return bs.to_string();
}

template<typename T> string to_string(queue<T> q) {
  string res = "{";
  size_t sz = q.size();
  while (sz--) {
    T cur = q.front();
    q.pop();
    if ((int) res.size() > 1) {
      res += ", ";
    }
    res += to_string(cur);
  }
  res += "}";
  return res;
}

template<typename T, class C> string to_string(priority_queue<T, vector<T>, C> pq) {
  string res = "{";
  while (!pq.empty()) {
    T cur = pq.top();
    pq.pop();
    if ((int) res.size() > 1) {
      res += ", ";
    }
    res += to_string(cur);
  }
  res += "}";
  return res;
}

template<typename T> string to_string(const T& v) {
  string res = "{";
  for (auto &el : v) {
    if ((int) res.size() > 1) {
      res += ", ";
    }
    res += to_string(el);
  }
  res += "}";
  return res;
}

template<typename A, typename B> string to_string(const pair<A, B>& p) {
  return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
template<typename A, typename B, typename C> string to_string(const tuple<A, B, C>& t) {
  return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ')';
}
template<typename A, typename B, typename C, typename D> string to_string(const tuple<A, B, C, D>& t) {
  return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ')';
}

void debug_out(int size, bool first, string name) {
  vector<string> tmp = {name};
  vector<int> tmp2 = {size, first};
  cerr << endl;
}

constexpr int buffer_size = 255;

template<typename Head, typename... Tail> void debug_out(int size, bool first, string name, Head H, Tail... T) {
  string tmp;
  int off = 0;
  while ((!name.empty() && name[0] != ',') || off != 0) {
    tmp += name[0];
    name.erase(name.begin());
    char c = tmp.back();
    if (c == '{' || c == '(') {
      ++off;
    } else if (c == '}' || c == ')'){
      --off;
    }
  }
  if (!name.empty()) {
    name.erase(name.begin());
  }
  if (tmp[0] == ' ') {
    tmp.erase(tmp.begin());
  }

  string buff = to_string(H);
  if ((int) buff.size() + size + (int) tmp.size() > buffer_size - 5 && !first) {
    cerr << '\n';
    size = 0;
  }
  cerr << '[' << tmp << ": " << buff << "] ";
  debug_out(((int) buff.size() + size + (int) tmp.size() + 5) % buffer_size, false, name, T...);
}

#ifdef DEBUG
#define debug(...) cerr << "-> ", debug_out(3, true, string(#__VA_ARGS__), __VA_ARGS__)
#define here cerr << "-> " << __LINE__ << endl
#else
#define debug(...) void(37)
#define here void(37)
#endif
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  const int inf = int(1e9) + 1;
  for (int i = 1; i < n; ++i) {
    debug(a[i] / a[i - 1], !!(a[i] % a[i - 1]));
    a[i] = min(inf, (a[i] / a[i - 1] + !!(a[i] % a[i - 1])) * a[i - 1]);
  }
  debug(a); 
  assert(is_sorted(a.begin(), a.end()));
  vector<tuple<int, int, int>> all;
  int lst = 0;
  for (int i = 0; i < n; ++i) {
    if (i == n - 1 || a[i + 1] != a[i]) {
      all.emplace_back(-i - 1, -lst - 1, a[i]);
      lst = i + 1;  
    }
  }
  assert(int(all.size()) < 40);                   
  while (q--) {
    int t, l, r;
    cin >> t >> l >> r;
    int ans = (t >= l && t <= r);
    for (auto[nl, nr, x] : all) {
      int go = t - (t % x);
      debug(nl, nr);
      debug(l - go, r - go);
      ans += max(0, min(nr, r - go) - max(nl, l - go) + 1);
    }
    cout << ans << '\n';
  }

}
# Verdict Execution time Memory Grader output
1 Correct 286 ms 20688 KB Output is correct
2 Correct 290 ms 20756 KB Output is correct
3 Correct 288 ms 20704 KB Output is correct
4 Correct 287 ms 20812 KB Output is correct
5 Correct 284 ms 20692 KB Output is correct
6 Correct 284 ms 20676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 20688 KB Output is correct
2 Correct 290 ms 20756 KB Output is correct
3 Correct 288 ms 20704 KB Output is correct
4 Correct 287 ms 20812 KB Output is correct
5 Correct 284 ms 20692 KB Output is correct
6 Correct 284 ms 20676 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 285 ms 19240 KB Output is correct
14 Correct 297 ms 19788 KB Output is correct
15 Correct 295 ms 18484 KB Output is correct
16 Correct 291 ms 19164 KB Output is correct
17 Correct 375 ms 23244 KB Output is correct
18 Correct 388 ms 23260 KB Output is correct
19 Correct 377 ms 23364 KB Output is correct
20 Correct 372 ms 23236 KB Output is correct
21 Correct 392 ms 23252 KB Output is correct
22 Correct 377 ms 23212 KB Output is correct
23 Correct 370 ms 23108 KB Output is correct
24 Correct 370 ms 23256 KB Output is correct
25 Correct 289 ms 20740 KB Output is correct
26 Correct 303 ms 20864 KB Output is correct
27 Correct 377 ms 22796 KB Output is correct
28 Correct 398 ms 23064 KB Output is correct
29 Correct 412 ms 22744 KB Output is correct
30 Correct 396 ms 22892 KB Output is correct
31 Correct 395 ms 23108 KB Output is correct
32 Correct 286 ms 19400 KB Output is correct
33 Correct 1 ms 204 KB Output is correct