Submission #677193

#TimeUsernameProblemLanguageResultExecution timeMemory
677193IliyaStrange Device (APIO19_strange_device)C++17
100 / 100
1094 ms63256 KiB
#include<bits/stdc++.h> #define F first #define S second #define pb push_back #define Sz(x) int((x).size()) #define All(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; const int N = 1e5 + 10; const ll INF = 1e18; const int MOD = 1e9 + 7; ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } map<ll, ll> PS; ll n, l, r, A, B, G, P, pos, ans, last; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); scanf("%lld%lld%lld", &n, &A, &B); G = gcd(A, B + 1); P = (INF / B < A / G ? INF : A / G * B); for(int i = 0; i < n; i++) { scanf("%lld%lld", &l, &r); if(r - l + 1 >= P) return !(printf("%lld", P)); l %= P, r %= P; if(l <= r) PS[l]++, PS[r + 1]--; else PS[0]++, PS[r + 1]--, PS[l]++, PS[P]--; } for(auto x : PS) { if(pos) ans += x.F - last; pos += x.S; if(pos) last = x.F; } printf("%lld", ans); return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%lld%lld%lld", &n, &A, &B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
#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...