Submission #1099495

#TimeUsernameProblemLanguageResultExecution timeMemory
1099495Zero_OPStrange Device (APIO19_strange_device)C++14
100 / 100
559 ms100324 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i) #define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i) #define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i) #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } using ll = long long; using ld = long double; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); } template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); } void testcase(){ int n; ll A, B; cin >> n >> A >> B; ll cycle; if(A / __gcd(A, B + 1) > 1e18 / B || A / __gcd(A, B + 1) * B > 1e18){ cycle = LLONG_MAX; } else{ cycle = A / __gcd(A, B + 1) * B; } map<ll, int> diff; rep(_, 0, n){ ll l, r; cin >> l >> r; if(r - l + 1 >= cycle){ cout << cycle << '\n'; return; } l %= cycle; r %= cycle; if(l <= r){ diff[l] += 1; diff[r + 1] -= 1; } else{ diff[0] += 1; diff[r + 1] -= 1; diff[l] += 1; diff[cycle] -= 1; } } int sum = 0; ll ans = 0, last = 0; for(auto [pos, val] : diff){ if(sum > 0){ ans += pos - last; } sum += val; last = pos; } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define filename "task" if(fopen(filename".inp", "r")){ freopen(filename".inp", "r", stdin); freopen(filename".out", "w", stdout); } int T = 1; //cin >> T; while(T--) testcase(); return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'bool minimize(T&, const T&)':
strange_device.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |     if(a > b) return a = b, true; return false;
      |     ^~
strange_device.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
strange_device.cpp: In function 'bool maximize(T&, const T&)':
strange_device.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   20 |     if(a < b) return a = b, true; return false;
      |     ^~
strange_device.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   20 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
strange_device.cpp: In function 'void testcase()':
strange_device.cpp:69:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     for(auto [pos, val] : diff){
      |              ^
strange_device.cpp: In function 'int main()':
strange_device.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(filename".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(filename".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...