Submission #19291474


Source Code Expand

Copy
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

// sum x=0..n-1 (ax+b)/c
int64 get(int64 a, int64 b, int64 c, int64 n) {
  if (!a) return b / c * n;
  int64 ret = 0;
  ret += b / c * n; b %= c;
  ret += a / c * n * (n - 1) / 2; a %= c;
  if (a * n + b < c) return ret;
  return ret + get(c, (a * n + b) % c, a, (a * n + b) / c);
}

int main() {
  int cas;
  cin >> cas;
  while (cas--) {
    int64 A, B, C, D;
    cin >> A >> B >> C >> D;
    int64 m = (D - 2) / (C - B);
    int64 L = get(B, A - 1, D, m + 1);
    int64 R = get(C, A, D, m + 1);
    trace(L, R, m);
    int64 ret = m - (R - L);
    cout << ret << '\n';
  }
  return 0;
}

Submission Info

Submission Time
Task E - Simple Math 3
User cuiaoxiang
Language C++ (Clang 10.0.0)
Score 800
Code Size 3153 Byte
Status AC
Exec Time 54 ms
Memory 3184 KB

Compile Error

./Main.cpp:78:42: warning: unused variable 'inf' [-Wunused-const-variable]
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
                                         ^
./Main.cpp:79:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
          ^
2 warnings generated.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status AC
AC × 21
Set Name Test Cases
Sample
All example_00, max_random_00, max_random_01, max_random_02, max_random_03, max_random_04, max_random_05, max_random_06, max_random_07, max_random_08, max_random_09, small_00, small_01, small_02, small_03, small_04, small_bc_00, small_bc_01, small_bc_02, small_bc_03, small_bc_04
Case Name Status Exec Time Memory
example_00 AC 11 ms 2988 KB
max_random_00 AC 43 ms 3132 KB
max_random_01 AC 45 ms 2996 KB
max_random_02 AC 42 ms 3136 KB
max_random_03 AC 41 ms 3036 KB
max_random_04 AC 46 ms 3136 KB
max_random_05 AC 46 ms 3084 KB
max_random_06 AC 42 ms 3184 KB
max_random_07 AC 43 ms 3180 KB
max_random_08 AC 44 ms 3152 KB
max_random_09 AC 42 ms 3080 KB
small_00 AC 31 ms 3080 KB
small_01 AC 23 ms 3088 KB
small_02 AC 30 ms 3124 KB
small_03 AC 29 ms 3024 KB
small_04 AC 23 ms 3140 KB
small_bc_00 AC 54 ms 3184 KB
small_bc_01 AC 50 ms 3132 KB
small_bc_02 AC 52 ms 2992 KB
small_bc_03 AC 51 ms 3140 KB
small_bc_04 AC 52 ms 3144 KB