Submission #304825

#TimeUsernameProblemLanguageResultExecution timeMemory
304825HemimorStrange Device (APIO19_strange_device)C++14
100 / 100
799 ms69148 KiB
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <cassert> #include <bitset> #include <vector> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<P,int> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; ll gcd(ll a,ll b){ if(!b) return a; return gcd(b,a%b); } typedef __int128 b128; int n; ll A,B,res=0; int main(){ scanf("%d%lld%lld",&n,&A,&B); b128 m=A/gcd(A,B+1)*b128(B); vector<pair<ll,int>> a; for(int i=0;i<n;i++){ ll l,r; scanf("%lld%lld",&l,&r); if(r-l+1>=m){ cout<<(ll)m<<endl; return 0; } l%=m,r%=m; r++; a.push_back({l,1}); a.push_back({r,-1}); if(l>r){ a.push_back(make_pair(0LL,1)); a.push_back(make_pair((ll)m,-1)); } } sort(a.begin(),a.end()); ll N=a.size(),x=0,s=0; for(int i=0;i<N;i++){ ll y=a[i].first,t=a[i].second; if(s) res+=y-x; x=y,s+=t; } printf("%lld\n",res); }

Compilation message (stderr)

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