Submission #933754

#TimeUsernameProblemLanguageResultExecution timeMemory
933754irmuunStrange Device (APIO19_strange_device)C++17
100 / 100
418 ms71472 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,a,b; cin>>n>>a>>b; ll l[n+5],r[n+5]; ll g=a/gcd((b+1)%a,a),MX=1e18+1; if(MX/b>=g){ g=g*b; } else{ g=MX; } for(ll i=1;i<=n;i++){ cin>>l[i]>>r[i]; } vector<pair<ll,ll>>v; for(ll i=1;i<=n;i++){ if(r[i]-l[i]+1>=g){ cout<<g; return 0; } ll L=l[i]%g,R=r[i]%g; if(L<=R){ v.pb({L,R}); } else{ v.pb({0,R}); v.pb({L,g-1}); } } sort(all(v)); ll ans=0; for(ll i=0;i<v.size();){ ll nxt=i,curR=v[i].ss; while(nxt+1<v.size()&&v[nxt+1].ff<=curR){ nxt++; curR=max(curR,v[nxt].ss); } ans+=curR-v[i].ff+1; i=nxt+1; } cout<<ans; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:44:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(ll i=0;i<v.size();){
      |                ~^~~~~~~~~
strange_device.cpp:46:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         while(nxt+1<v.size()&&v[nxt+1].ff<=curR){
      |               ~~~~~^~~~~~~~~
#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...