Submission #1032702

#TimeUsernameProblemLanguageResultExecution timeMemory
1032702KasymKStrange Device (APIO19_strange_device)C++17
20 / 100
296 ms26976 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int MOD = 1e9+7; const int N = 1e5+5; const ll INF = 1e18+1; int v[N]; int main(){ // freopen("file.txt", "r", stdin); int n; scanf("%d",&n); ll a, b; scanf("%lld%lld",&a,&b); ll ad = a/__gcd(a, b+1); if(ad <= INF/b) ad *= b; else ad = INF; vector<pii>v; for(int i = 1; i <= n; ++i){ ll l, r; scanf("%lld%lld", &l, &r); if(r-l+1 >= ad){ printf("%lld\n", ad); return 0; } l %= ad, r %= ad; if(l <= r) v.pb({l, r}); else v.pb({l, ad-1}), v.pb({0, r}); } sort(all(v)); pii as = {-1, -1}; ll ans = 0; for(auto i : v){ if(as.ss < i.ff){ if(as.ff != -1) ans += as.ss-as.ff+1; as = i; } else umax(as.ss, i.ss); } printf("%lld\n", ans+as.ss-as.ff+1); return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
strange_device.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%lld%lld",&a,&b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
strange_device.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   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...