Submission #1169550

#TimeUsernameProblemLanguageResultExecution timeMemory
1169550wiiStrange Device (APIO19_strange_device)C++20
35 / 100
330 ms17064 KiB
#include <bits/stdc++.h> using namespace std; typedef double db; typedef long long ll; typedef long double ld; #define int ll typedef pair<int, int> pii; #define endl "\n" #define lx (id << 1) #define rx (lx | 1) #define all(x) (x).begin(), (x).end() #define bit(i, mask) ((mask) >> (i) & 1) #define foru(i,a,b) for(int i = (a); i <= (b); ++i) #define ford(i,a,b) for(int i = (a); i >= (b); --i) #define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); template<typename T> bool maximize(T &res, const T &val) { if (res < val) { res = val; return true; } return false; } template<typename T> bool minimize(T &res, const T &val) { if (val < res) { res = val; return true; } return false; } const ll Linf = 0x3f3f3f3f3f3f3f3f; const int Inf = 0x3f3f3f3f; const ll Mod = 1e9 + 7; const int Lim = 1e6 + 5; // #define Sieve #ifdef Sieve vector<int> pr; vector<int> lpf; void Linear_sieve(int n = Lim) { pr.assign(1, 2); lpf.assign(n + 1, 2); for (int x = 3; x <= n; x += 2) { if (lpf[x] == 2) pr.push_back(lpf[x] = x); for (int i = 1; i < pr.size() && pr[i] <= lpf[x] && pr[i] * x <= n; ++i) lpf[pr[i] * x] = pr[i]; } } #endif // #define Ckn_calc #ifdef Ckn_calc const int LIM = 1e6 + 16; int fact[LIM + 10]; /// factorial: fact[n] = n! int invs[LIM + 10]; /// inverse modular: invs[n] = n^(-1) int tcaf[LIM + 10]; /// inverse factorial: tcaf[n] = (n!)^(-1) void precal_nck(int n = LIM) { fact[0] = fact[1] = 1; invs[0] = invs[1] = 1; tcaf[0] = tcaf[1] = 1; for (int i = 2; i <= n; ++i) { fact[i] = (1LL * fact[i - 1] * i) % Mod; invs[i] = Mod - 1LL * (Mod / i) * invs[Mod % i] % Mod; tcaf[i] = (1LL * tcaf[i - 1] * invs[i]) % Mod; } } ll C(int n, int k) { if (n < k || k < 0) return 0; ll res = fact[n]; res *= tcaf[k], res %= Mod; res *= tcaf[n - k], res %= Mod; return res; } ll P(int n, int k) { ll res = fact[n]; res *= tcaf[n - k], res %= Mod; return res; } #endif /// ====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*==== const int base = 3; const int N = 1e6 + 5; const int LOG = log2(N) + 1; const int dx[] = {+1, -1, 0, 0}; const int dy[] = {0, 0, +1, -1}; const int block = sqrt(N) + 2; int n, a, b; int l, r; void solve() { cin >> n >> a >> b; if (b == 1) if (~a & 1) a >>= 1; int flag = ((1e18) / a <= b); vector<pair<int, int>> seg; foru(i, 1, n) { cin >> l >> r; if (!flag) if (l + a * b - 1 <= r) return cout << a * b << endl, void(); if (!flag) { l %= a * b; r %= a * b; } if (l <= r) { seg.push_back({l, r}); } else { seg.push_back({0, r}); seg.push_back({l, a * b - 1}); } } sort(all(seg)); int last = 0; int ans = 0; for (auto &[l, r]: seg) { // cout << l << " " << r << endl; maximize(last, l); if (last <= r) ans += r - last + 1, last = r + 1; } cout << ans << endl; } signed main() { FastIO; #define task "test" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } #ifdef Sieve Linear_sieve(); #endif #ifdef Ckn_calc precal_nck(); #endif int ntest = 1; // cin >> ntest; while (ntest--) { //cout << "Case " << q << ": " << "\n"; solve(); //cout << "\n"; } return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:138:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:139:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  139 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...