Submission #403486

#TimeUsernameProblemLanguageResultExecution timeMemory
403486HazemStrange Device (APIO19_strange_device)C++14
100 / 100
636 ms49684 KiB
#include <bits/stdc++.h> using namespace std; #define LL long long #define F first #define S second #define pii pair<int,int> #define piii pair<pair<int,int>,int> const int N = 1e6+10; const int M = 200; const LL INF = 1e9; const LL LINF = 2e18; const LL MOD = 1e9+7; const double PI = 3.141592653589793; pair<LL,LL>p[N]; vector<pair<LL,LL>>vec; LL gcd(LL a,LL b){return !b?a:gcd(b,a%b);} int main(){ //freopen("out.txt","w",stdout); LL n,a,b,Len; scanf("%lld%lld%lld",&n,&a,&b); // for(int i=0;i<=n;i++) // printf("%d %d\n",(i+i/b)%a,i%b); LL g = gcd(a,b+1); a /= g; if(log(a)+log(b+1)>=log(LLONG_MAX)) Len = LINF; else Len = a*(b+1)-a; bool q = 0; for(int i=1;i<=n;i++){ scanf("%lld%lld",&p[i].F,&p[i].S); q |= p[i].S-p[i].F+1>=Len; p[i].F %= Len;p[i].S %= Len; if(p[i].S>=p[i].F) vec.push_back({p[i].F,p[i].S}); else vec.push_back({p[i].F,Len-1}),vec.push_back({0,p[i].S}); } sort(vec.begin(),vec.end()); LL l = 0,r = -1,ans = 0; vec.push_back({LINF,LINF}); for(int i=0;i<vec.size();i++){ if(vec[i].F>r) ans += r-l+1,l = vec[i].F,r = vec[i].S; else r = max(r,vec[i].S); } printf("%lld\n",q?Len:ans); }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<vec.size();i++){
      |                 ~^~~~~~~~~~~
strange_device.cpp:27:10: 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:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld%lld",&p[i].F,&p[i].S);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...